The heartbreak that Schoolmaster Yin felt that day fueled his rage and it prompted him to settle the score with Yu Yan and the man she chose over him.
That is why, as soon as he found out where the two lived, Schoolmaster Yin immediately went there.
Then everything happened exactly just like what Mu Ruochen told Mu Lingxi when he confessed the truth to her.
Fury and jealousy clouded Schoolmaster Yin's rationality when he saw that Yu Yan was already carrying a child of another man to her womb.
He was blinded by rage and all he wanted that time is something to quell the rage that was burning within him.
So to vent his frustration, Schoolmaster Yin put a curse at the child inside Yu Yan's womb.
Since he was capable of defying even his own death then, of course, he is more than capable of messing around with someone else soul.
Especially that of an unborn one.