It is possible to have units retreat to your base at any time. Retreating will cancel all negative effects as well as increase defense values and movement speed. However, the unit cannot be controlled until it reached the base via a more or less random path.
Failing to retreat a unit, especially when pinned down, often results in the loss of the whole group. Retreating too early loses offensive strength in battle. How do I recognize the best time to issue the command?