I may be mistaken, but what sticks in my head is that in taking a larger amount of air it somehow relaxes you, while at the same time allowing you to catch up on breathing. The reason you have to catch up is do to laziness in your lungs as you get tired. This is what I think is true from what I have heard in the past somewhere, however part of it, or the whole thing may be incorrect.
A yawn is a reflex of simultaneous inhalation of air and stretching of the eardrums, followed by exhalation of breath.
Yawning can occur when there is a need for expulsion of carbon dioxide from the body. It has been shown to control brain temperature, and can cool the brain. Stretching ones muscles could be a cause for yawning. Nervousness can trigger yawning, because the body has a need for action. http://en.wikipedia.org/wiki/Yawn
When you are tired it means your brain is not getting enough oxygen or there is not enough carbon dioxide. So when you yawn you take in more oxygen with a deep breath and it allows more oxygen to get to your brain and when you exhale you expel all the excess carbon dioxide from your body.