The ending of Sonic the Hedgehog 2 resolves the Master Emerald fight by turning Knuckles from an enemy into a teammate, and it quietly sets up Shadow for the next film.
What actually happens? In Green Hills, Robotnik builds a giant robot, and during the fight the Master Emerald breaks into seven Chaos Emeralds. Sonic uses them to become Super Sonic, wrecks the machine, and Robotnik is lost along with it. Knuckles then repairs the Master Emerald, and he, Sonic and Tails agree to guard it as a team. A scene in the credits points to a secret G.U.N. facility tied to Project Shadow.
Why does Knuckles switch sides? In my opinion, the film sets this up earlier than it first appears. Robotnik betrays Knuckles, takes the Emerald and leaves both him and Sonic to drown, so Knuckles loses his ally at the same moment he shares a problem with his rival. Tails then arrives in a biplane and rescues them, and that rescue is the first time the three act together. By the finale, the promise to protect the Emerald is a continuation of something already in motion.
How does it compare with the first film? Sonic the Hedgehog (2020) ended with Sonic sending Robotnik to the Mushroom Planet and settling in with Tom and Maddie, after a story about a hedgehog living in hiding and lonely enough to knock out power across a region. The sequel answers that loneliness from the other direction. It could be argued that the Super Sonic transformation is the crowd pleaser, but the repaired Emerald and the three way promise are what close the story, because Sonic now has friends of his own kind as well as a human family.
That being said, Robotnik going down with his machine is not a clean exit. The credits scene is the real hint: Agent Stone overhears G.U.N. talk about Project Shadow, and sonic the hedgehog 3 picks it up by showing Shadow captured by G.U.N. in 1974 and studied by Professor Gerald Robotnik. Paradoxically, the villain who seems finished here is the one who returns, with Jim Carrey credited as both Ivo Robotnik and Gerald Robotnik in the third film.