I read somewhere (unable to find citation) where people studied big cats, and their yawning pattern. They noticed that they would all start yawning prior to heading out to hunt, and suspected that, like people have posted, it boosts alertness. It would be contagious because once the leader decided to go hunt, everyone else was obliged to join in and do the same. This is why people correlate contagious yawning with pack leadership.
I practice Tai Chi, and there's a series of warm-up exercises that involve opening the airways by raising the arms, while opening the mouth wide. It may be the power of suggestion, or a trick of conditioning (the body sees a pattern and predicts imminent exercise and starts pre-dosing adrenaline) but it always makes me feel much more alert, and regularly triggers a real yawn, despite being fully awake and rested.