A person stretches involuntarily because it increases blood flow to the muscles, reduces stiffness of joints and prevents injuries. Most people stretch after waking up because muscles and joints have been stiff for a long time.
Blood tends to settle in some parts of the body while sleeping, and an involuntary stretch improves blood circulation. Many people also stretch involuntarily after sitting in a place for a long time to prevent stiffness and injury of muscles. A full-body stretch before and after exercising reduces muscle soreness and injury; however, this stretch must be done gently, as aggressive stretching can lead to strained muscles, ligament tears and other injuries.