Hang on to your Tesseracts! Apparently, in
Endgame[/em], when the Avengers
traveled back to 2012 to swipe various things from the 2012 Avengers, they inadvertantly
started a branch in time where Loki ended up with the Tesseract. Of course, once that
occurred, the Time Variance Authority quickly spotted him as a Deviant and quickly recruited
him to help in their fight against even more deviant Deviants.
— Michael Main