Well,
it's nice and warm in the womb, so you'd forgive the baby if it yawns.
Using 4D ultrasound, scientists have captured the fetal yawn and suggested
that it may be related to brain development:

Reissland and others used 4D ultrasound scans to capture a rapid sequence
of images for eight female and seven male foetuses at 24, 28, 32 and
36 weeks of gestation. All the unborn babies were healthy and were scanned
for 20 minutes. The researchers went through the images frame by frame
and counted the yawns and other movements made by the babies. Over 58
scans, the team recorded 56 yawns and 27 other mouth movements. Yawns
can be distinguished from other movements because a yawning mouth opens
more slowly than it closes.

When the scientists analysed the images they found similar yawning
rates in boys and girls. But, more surprisingly, yawning decreased steadily
from nearly twice every 10 minutes in foetuses at 24 weeks gestation,
to none at 36 weeks. The research appears in the journal Plos One.

"Unlike us, foetuses do not yawn contagiously, nor do they yawn
because they are sleepy. Instead, the frequency of yawning in the womb
may be linked to the maturing of the brain early in gestation,"
Reissland said.

"Given that the frequency of yawning in our sample of healthy
foetuses declined from 28 weeks to 36 weeks gestation, it seems to suggest
that yawning and simple mouth opening have this maturational function
early in gestation."