It's psychological. The best explanation of it I've heard is that yawning serves to aid the brain in getting more oxygen, something to help fight fatigue. In pre-civilization tribal groups, if you're tired, it's almost certain that the people traveling/working alongside you are also tired. Yawning thus is effectively also a way of subconsciously telling the group that, "Hey, I'm tired. Are you tired? Perhaps we should all wake up a bit and pay attention to our surroundings some more."
It's a group survival mechanism, and an ancient one at that, seeing as animals like dogs and cats also yawn.
They are contagious, not infectious. No one knows the exact answer and all we really have is some speculation as to why.
It's a sign of empathy. One sign of a psychopath is that they don't "catch" a yawn. Humans can even catch yawns from other animals.
Only one other animal on earth can catch a yawn from another species...
Dogs! My dog always yawns in response to my yawns!
I've also heard that yawning was a mechanism in early man to signify safety. When we were more nomadic, people at the front or back of a group of traveling people would yawn. The yawn would then pass through the group, showing that currently there was no danger.