For that you'll first have to understand what happens when we breathe. Normally, when you breathe in, you inhale oxygen and your body uses it up. The body makes a waste product called as carbon dioxide that is exhaled from the lungs when you breathe out.
When you are sleepy, bored or tired, you breathe more slowly. Your body requires oxygen and needs to throw out the carbon dioxide. So, your brain makes you take an extra breath, which is deep and long called a yawn, so that you can take in more of oxygen and give out carbon dioxide fully.
Now, next time, if your teacher asks you, "why are you yawning?", you can say that her class is boring and your body needs oxygen for which your brain has sent a message to your lungs to take an extra deep breath called the yawn.
Watch out for next lecture by your teacher on "Good mannerisms"!!!