There are actually quite a few theories about what lies behind a yawn. A long-standing theory marks as cause for the yawning the lack of oxygen and excess of carbon dioxide in the blood. When the brain detects this it triggers the yawn reflex when the mouth opens wide and the lungs inhale deeply, while the abdominal muscles flex and the diaphragm is pushed down, making way for the much needed oxygen. But, according to this site, there has been an experiment testing this theory. It has been observed both that giving more oxygen to people didn't decrease yawning, and that decreasing the amount of carbon dioxide in the environment didn't prevent yawning either. So the aforementioned theory is most likely a false one. Even though it has been taught in medical school for quite a while.
Another theory, this time verified at least partially, is that yawns are caused by the same chemicals in the brain that affect mood, emotions or appetite, chemicals such as serotonin, dopamine or glutamic acid. As more of these compounds are activated in the brain, the frequency of yawning increases. It has been observed that a greater presence of endorphins in the brain reduces yawning, while people taking serotonin inhibitors have been observed yawning abnormally often.
There is also a third theory sustaining that yawning is an activity similar to stretching, because it increases blood pressure and heart rate and also flexes some muscles and joints. Another argument in favor of this theory is the fact that when trying to stifle a yawn by clenching your jaw shut, the yawn is very unsatisfying. :)
There is also a thing like the Evolution Theory, claiming that yawning is something that begun in the far past, when our ancestors used yawning to show their teeth and intimidate others, or the so-called Boredom Theory, claiming that we yawn when we are bored, tired or drowsy. But of course those latter theories not only are not proven to be true but they also raise some question marks, so they are most likely speculations only.
In the end the truth is that, despite the theories we might have, we actually don't know what actually causes a yawn, especially as, for example, fetuses have been observed yawning in the womb or some male animals (men included) have been noticed yawning associated with penile erection.
As a fun fact, yawning is employed by a species of penguins as part of their courting ritual, when a male gets in front of the chosen female and opens its beak with its face pointed upwards.