Opinions vary on this, but there is no definitive answer.
The latest theory is that it's an alarm signal which we hold over from our primitive ancestors. Primeval apes, sighting danger, would yawn to simultaniously draw back their lips from their fangs, signalling a willingness to fight, and also silently to alert the other members of the tribe.
The 'oxygen increase' theory has had a bit of a battering because we now know that foetuses yawn during their deveolpment, and they are not breathing air, so that idea is now largely discounted.