People usually yawn when we're tired, bored, or stressed. But no one's sure exactly why we yawn. It's been proposed that yawning regulates oxygen flow or controls body temperature. Maybe yawning was a territorial reflex ("Look at my big teeth and how few shits I give about you!") or a herd instinct ("Guys I'm tired, let's all go to bed.") We really don't know.
We do know that yawns are 'contagious' among humans. You have all watched people around you follow your lead when you yawn, or have struggled to contain a yawn of your own after seeing someone else's. Even dogs yawn in response to seeing humans yawn. We're not sure why yawning is contagious either, but it may be an empathetic reaction to the displayed feelings of other people. People are more likely to mimic the yawns of people related to them and ignore the yawns of strangers (check it), so it looks like social solidarity has a lot to do with it.
Just reading about yawning can trigger yawns. I must have yawned twenty times while writing this post. Did you yawn while reading it?