My textbook says "As the seed matures it loses water and enter dormancy". I am confused as to whether this happens before the seeds are transported or after, and as to how seeds know to become dormant when required and then become active again.
I presume what the author is trying to convey is that as a seed ages, it enters a quiescent phase as a result of natural desiccation. Without more context, I'd guess that the quote you've provided here is referring to secondary dormancy, which is a response to unfavorable germination conditions. By definition, secondary dormancy occurs after the seed is released from the plant.
The mechanisms of secondary dormancy are not well understood, and resumption of embryonic function could be dependent on any number of factors. Generally, dormancy continues until such time as favorable conditions are observed by the dormant seed. For Avena sativa, seeds become dormant if temperatures in excess of the maximum for germination are observed. Other seeds become dormant in response to over- or dehydration, temperature variability, age, other factors, and combinations ad nauseum.
Some of the more common environmental causes of exiting dormancy include afterripening, chilling and lighting.