The answer to the question why we yawn is not entirely clear. One theory states that yawning oxygenates the brain, and another that it cools the brain. Recent research tends to lean towards the second variant. The brain works better and falls asleep.
Yawning also has a social function. It is a so-called contagion, where we yawn if we hear or see someone yawn. We yawn even when we read or talk about yawning. The aim is to strengthen social ties between the members of the group in which we find ourselves.