Why do babies pandiculate too much

Why do humans and animals stretch their bodies and what causes this behavior?

Humans and other animals have many innate behaviors that are not learned from observation, that is, behaviors that are intrinsically linked to our nervous system, and this is one of them. Mammalian sucking reflexes and the Moro reflex are human babies (which we outgrow) are other simple examples.

The stretching behavior you are referring to is usually called in humans Called pandiculation (defined as involuntary stretching of the soft tissues), and yawning is often viewed as a special case. These behaviors are usually also related to transition times between high and low activity in animals (Walusinskie, 2006). In practice, stretching acts as a means of reversing muscle atony during REM sleep and, in this sense, as a means of restoring homeostatic functions (Fraser, 1989; Walusinskie, 2006).

An article by Rial et al. (2010) looks at the development of sleep and wakefulness in mammals of our reptilian predecessors, and suggests that stretching behavior may be due to post-sunbathing activities, particularly risk assessment behaviors such as sunbathing.

... Risk Assessment Behavior (RAB) and consists of the cancellation of the current behavior, which is replaced by head-diving movements, eye scanning, straightening and taking stretching postures ...

There is most likely much more to be said, and the paper cited above has many references that can provide further clarification and evidence. A brief comparative discussion of pandiculation can be found in Frasier (1989).