No one knows for sure how stretching actually works. There's some evidence to suggest that stress applied to a muscle in just the right way causes it to lengthen or stretch. Other researchers say stretching increases flexibility because the muscle itself is elastic. With a constant stretch, the muscle will relax and increase in length.
It's also possible that using one set of muscles keeps the opposite group of muscles from contracting at the same time. This causes the opposing muscles to relax, loosen, and stretch.
We're not sure about the effect of other factors on stretching. Maybe age, gender, and number of hours in one position each day make a difference in how far the muscles will stretch. More studies are needed to answer these (and other) questions.