The Emperor didn’t sleep with Mirang. In the raws, Garyun was disguised as the red haired Sancheong and assisting Yeon on the case. You can tell it’s him because of the eye colour. It’s a warm grey (the Emperor’s real eye colour) compared to the actual Sancheong with a cooler light grey. The “Emperor” that Mirang gives the aphrodisiac to and sleeps with is actually the guy who Yeon fought against in the theatre. If you look at his eyes in the last scene of the season, it’s black. I believe the theatre dude agreed to disguise as the Emperor so Garyun could sneak out of the palace and help Yeon without her knowing that it’s actually him.
Anyways, the real father of Mirang’s child is the theatre guy. I think his name is Kwak Amil? The Emperor is innocent!
I read it at novelupdates spoilers here is the link https://forum.novelupdates.com/threads/yeon-lokheun-%EC%97%B0%EB%A1%9D%ED%9D%94.112743/page-4
I wished for Mi Rang to die T.T so that scene in the novel won't happen to the Emperor.