We generally Yawn when we are tired, stressed or bored. There are many theories and reasons for yawn to occur.
Most accurate is generally when we are tired, stressed or bored the amount of air we inhale becomes less. This may result in increase of Carbondioxide in our blood. Hence we yawn so as to take more amount of air into our body thus the requirement of oxygen is achieved.