Science says it is the reaction of the body when the oxygen level goes down.
Tvashta ( a form of Sun god ) had a son called Trishiras. His mother belonged to the asura clan. Trishiras was made the priest of devas. Owing allegiance to both sides, Trishiras while offering oblations to devas also shared them clandestinely with the asuras. Indra came to know about this and beheaded him.
Agitated, Tvashta performed a soma yaga. He did not invite Indra to it. However, Indra came in and forcibly drank the soma and went away. Tvashta poured the remaining soma in Agni and chanting mantra created an asura called Vritra to kill Indra. Vritra started expanding his body and enveloping the three worlds. In the process, Agni and Soma got trapped inside Vritra's mouth.
Upon seeing the enormity of his enemy Indra approached Brahma who gave him Vajrayudha with which to kill Vritra. As Indra approached Vritra, Agni and Soma stopped him for the fear of getting themselves also killed as they were inside Vritra's body. Indra asked them come out. They wanted something in returm, Indra offered them a share of oblations during Purnamaseshti.
They didn't know how to come out. Indra created Sheetajvara ( cold and fever / flu ) and attacked Vritra with it. Vritra fatigued with fever yawned and thus came out Agni and Sona. Together with them prana and apana also left Vritra's body.
Hence if a yajamana who is under deeksha for yajna yawns he should chant a certain mantra immediately to restore prana and apana in his body.
Yawning helped Indra himself later on in the fight. Vritra swallowed Indra. Devas panicked and tried all ways and means to get Indra out. They struck Vritra with 'yawning' and through his gaped mouth Indra came out.
This is how yawning started.
This is how yawning started.