The physical and psychological sequences which occur during the yawning process have been widely studied. But identifying an evolutionary reason to explain the need for yawning are not clear.
As Wikipedia puts it : ““There are a number of theories that attempt to explain why animals yawn. It is likely that there are a number of triggers for the behavior. However, there are a few select theories that attempt to explain the primary evolutionary reason for the yawn. None of them has been empirically substantiated.”” source
Yawns are common not only in most species of mammals, but also occur in reptiles, and even fish - suggesting a very deep-rooted, but as yet unknown origin.
Also see: Contagious Yawning