Many factors may contribute to a forward stooped posture. Some people are able to remain upright throughout their life, so there may be individual or genetic factors here, too.
Gravity has a strong effect on posture. The natural effect of this force is to pull us forward. Inactivity with increased time sitting may be part of the problem. The flexor muscles of the hip can even become shortened from being in a chronically contracted state.
Postural changes can begin to alter the way the muscles contract. Studies show that the multifidus (a deep muscle of the spine) increases in size as it contracts. This has been shown when moving from one position to another such as from prone to upright.
This same muscle decreases in size as the body stoops forward. Changes in strength, size and control of the muscle may contribute to a forward stooped posture. More studies are needed to answer your question fully. Exactly what happens as we age isn’t entirely clear yet.
For now, it seems an active lifestyle with regular activity and standing up straight are your best tools to prevent postural changes. Exercises to stretch the front (flexor muscles) of the body and strengthening exercises for the back (extensor muscles) are especially important.