He's known this for a while now. Its why he's been pushing for delays to his trials, so he can just get another chance at being elected and then never leaving power again.
Watch the video of him on election night 2016. While everyone else is celebrating that they actually pulled off a really impressive underdog win, Trump himself looks rather morose. He looks like a guy who just realized that he's moved out of the realm of "screed-oriented media grifter surrounded by sycophants" into an arena where lying has consequences, criminality can't easily be dismissed and for the first time in his life his opponents will be just as if not more powerful than him. I think that day was the day he realized he's either gonna be king for life or he's going to prison.