So far, Loki has revealed that everything that takes place in the Marvel Cinematic Universe is part of a “Sacred Timeline” preserved and maintained by a mysterious group of immortal beings known as “Time-Keepers.”
These Time-Keepers use the TVA to monitor and repair this one universe from any deviation from their grand plan.
When Loki stole the Tesseract during Avengers: Endgame, that wasn’t supposed to happen, making him a “Variant” time criminal and landing him at the TVA.
But when the Avengers took the Infinity Stones to stop Thanos in Endgame, that apparently was supposed to happen, and thus the Sacred Timeline was maintained.