If we are in a simulation, maybe yawning is an animation glitch.
As far as I know, the purpose of yawning isn't really understood, but it's present in nearly all land vertebrae. Maybe it's a universal bug in the breathing animation code.
That's easy to check. I'm currently insanely jet lagged and super tired, yawning every few minutes. My pulse oximeter is indicating 99% saturation, so that's not it.
Edit: on the other hand, I'm a flight attendant, so my body is used to lower oxygen atmospheres, so I usually have >98% O2 levels.
According to the above, they suspect it has to do with helping to keep you relative alert/awake but also, possibly to cool the brain and adjust ear pressure.