Misconception : Severus Snape stayed in the light side for the sole purpose of saving Harry for Lily. He was a Voldemort supporter at heart till his death. He never believed in Order’s cause. He didn’t care about saving the Wizarding World.
Snape came to know about Harry’s fate during Half-Blood Prince’s timeline, that is, Harry has to die to end Voldemort to bring peace to the wizarding world. But this meant Snape’s whole commitment to Lily became meaningless because Harry Potter, whom Snape had been protecting so religiously all those years for Lily, had to die.
So if Severus was still a Voldemort supporter at heart, if he didn’t believe in Order’s cause, if he was in the light side for the sole purpose of saving Harry for Lily, then he could have ditched the Order/Light side after he got to know about Harry’s fate during Half-Blood Prince or atleast after he killed Dumbledore. He anyway became a betrayer in the eyes of Order after he (mercy) killed Dumbledore, so he could have easily f*cked off and supported Voldemort again. But even after he got to know that his commitment to Lily had become meaningless, he stayed loyal to the Light side because he also believed in Order’s cause.
He understood that saving the wizarding world was more important than saving one boy’s life. He cared enough about saving the wizarding world that he agreed to appear as a villain by killing Dumbledore.
Yes his initial motivation to change sides was to keep Lily safe. Yes Lily was his motivation for taking such a personal interest in saving Harry throughout those years (who would risk their life repeatedly to save a random kid’s life), but that doesn’t mean he never got himself to believe in Order’s cause. Lily getting threatened was like the “wake up” call which led Severus to realise how wrong Voldemort was. He truly evolved. He fought and even died for the Order’s cause.
The following are some of those actions which Severus took after he got to know about Harry’s fate, actions which had nothing to do with Lily :
In Deathly Hallows, Severus Snape ordered the portrait of ex-headmaster Phineas Nigellus Black to not use blood-purist slur against Hermione. He didn’t allow even a magical portrait to slander his student based on her “blood purity”. After that, Snape helped Harry Potter by sending his Patronus to guide Harry towards the Gryffindor’s sword.
In Deathly Hallows (by this time he knew Harry had to die and Dumbledore was also dead), Severus went out of his way to save Remus Lupin’s life at great risk to his own life during Seven Potters Battle when a Death Eater was about to kill Remus. He saved him despite the fact that he was supposed to be acting like a DE there and Lord Voldemort was himself participating in the Battle! Saving Remus had got nothing to do with Lily.
When Dumbledore asked him, “How many men and women have you watched die?” Severus regrets - “Lately, only those whom I couldn’t save”. Again saving other people from DEs or Voldemort had got nothing to do with Lily. “Men and women” clearly implies victims of the Death Eaters, and not Hogwarts children. This conversation happened during HBP’s timeline and by that time, Voldemort and the Death Eaters had already started to cause open havoc and terror in the wizarding as well as muggle worlds. So Severus tried to save as many lives from DEs as possible. Saving other people’s lives had nothing to do with Lily. He saved them in order to atone for his past mistake.
In Deathly Hallows, Severus as headmaster tried to protect the Hogwarts students from cruel Carrows as much as possible without breaking his cover. Example, he gave Neville, Luna and Ginny a harmless detention with Hagrid as “punishment” when they tried to steal the Gryffindor’s sword from headmaster’s office. He kept the Carrows under limit. Not a single casualty occured that year at Hogwarts. Harry was even not at Hogwarts that year, so saving other Hogwarts students had nothing to do with Lily.
Dumbledore had instructed Snape to inform Harry about his fate only when Voldemort started keeping his snake Nagini safe beside him under magical protection. So during the war, when Severus noticed the snake being safe beside Voldemort, he begged the Dark lord 4 times to let him bring Harry Potter to him. He begged him so that he could go and give Harry the necessary information. Gave Harry his memories to help him defeat a terrorist and save the wizarding world. Severus died for the cause.
He chose saving the wizarding world over his commitment to Lily. His was a tale of redemption.