Yawning was for humans, and in some species still is, a signal to others in the group that it is time to go to sleep. Group's that 'bedded down' together not only reinforced the group bond, and individual bonds between members, it also ensured no member was left out alone, susceptible to predation.
So when one member yawns, and a chain reaction is set off, everybody realises it is time for bed and survival chances are increased.