Moriarty knew he was to die in The Reichenbach Fall, not Sherlock. So he knew Sherlock wud plan something to escape. The Final Game was going to be the death of both Mycroft and Sherlock.
In short, the whole series, with episodes the had the reference of Jim, was planned a long time ago with Eurus.
And the Governor said that Eurus had changed after the "Christmas Present", which means, after those 5 minutes, she messed with some brains and that's how she would contact Jim. Maybe, later when the governor found out that Eurus was messing with ppl, he went to talk to her, and she hypnotised him too. Thus, she had the control of the prison.