A University of Nottingham team found it occurs in a part of the brain responsible for motor function.
The primary motor cortex also plays a part in conditions such as Tourette's syndrome.
So the scientists say understanding contagious yawning could also help understand those disorders too.
Contagious yawning is a common form of echophenomena - the automatic imitation of someone else's words or actions.
Echophenomena is also seen in Tourette's, as well as in other conditions, including epilepsy and autism.
To test what's happening in the brain during the phenomenon, scientists monitored 36 volunteers while they watched others yawning.
In the study, published in the journal Current Biology, some were told it was fine to yawn while others were told to stifle the urge.
The urge to yawn was down to how each person's primary motor cortex worked - its "excitability".
And, using external transcranial magnetic stimulation (TMS), it was also possible to increase "excitability" in the motor cortex and therefore people's propensity for contagious yawns.
Georgina Jackson, professor of cognitive neuropsychology who worked on the study, said the finding could have wider uses: "In Tourette's, if we could reduce the excitability we might reduce the ticks, and that's what we are working on."
Prof Stephen Jackson, who also worked on the research, added: "If we can understand how alterations in cortical excitability give rise to neural disorders we can potentially reverse them.
"We are looking for potential non-drug, personalised treatments, using TMS that might be effective in modulating imbalances in the brain networks."
Dr Andrew Gallup, a psychologist at State University of New York at Albany, who has carried out research into the connection between empathy and yawning, said using TMS was a "novel approach" to the study of contagious yawning.
He added: "We still know relatively little about why we yawn. Various studies have proposed links between contagious yawning and empathy, yet the research supporting this connection is mixed and inconsistent.
"The current findings provide further evidence that yawn contagion may be unrelated to empathic processing."