Lack of oxygen is the easy answer, which is why we yawn when tired or when waking up.
However, as whonunuwho noted (say that fast five times!), yawning is also notoriously 'contagious.'
A personal take on this question: Four years ago I adopted a wonderful little Bichon/terrier rescue dog named Bungee. Every morning, he wakes up at sunrise, and he wakes up instantly. This often results in him developing hiccups, the spasms of which are caused by a lack of oxygen due to his very abrupt transition from fast asleep to wide awake.
I find that if I direct an exaggerated yawn at him, he will start yawning as well, and the hiccups will stop.