In particular animals
A stag's penis forms an S-shaped curve when it is not erect, and is retracted into its preputial sheath by the retractor penis muscle.
In Tandonia, the retractor penis inserts at the boundary between the penis and epiphallus.
In stallions, the retractor penis muscle is relatively underdeveloped. The retractor muscle contracts to retract the penis into the sheath and relaxes to allow the penis to extend from the sheath.
In bulls, protrusion is not affected much by erection, but more by relaxation of the retractor penis muscle and straightening of the sigmoid flexure.
References
Retractor muscle of the penis Wikipedia(Text) CC BY-SA