The season two finale of The Mandalorian was full of plenty of surprises, but the biggest was the appearance of Luke Skywalker (Mark Hamill) as he arrived just in time to save Din Djarin (Pedro Pascal), Bo-Katan Kryze (Katee Sackhoff), Fennec Shand (Ming-Na Wen), Cara Dune (Gina Carano), and the rest from Moff Gideon's (Giancarlo Esposito) Dark Troopers and take Baby Yoda (himself) away for Jedi training.
Getting to see Luke Skywalker in his prime was quite the thrill and you would imagine that such a moment would have been planned out from the very beginning, but that doesn't seem to be the case. While speaking with the WGA, The Mandalorian creator Jon Favreau said that Luke Skywalker's appearance wasn't always in the cards and only came to him as writing for the season progressed.
The story unfolded as I wrote it. The Mandalorian inherits a great deal from existing Star Wars stories, and when I write, that context is always a consideration. It became clear that, within the established continuity, certain things were likely to transpire.
Although we know the beginning and end of Luke Skwalker's tale, there's quite a lot of unexplored territory between the events of Return of the Jedi and The Force Awakens. "We have a tremendous amount of freedom afforded to us because of the gap in time between the films," Favreau said. "Dave Filoni and I are in constant discussion regarding how each story choice is impacted by, and would impact, existing Star Wars material." It remains to be seen whether or not we've seen the last of Luke Skywalker on The Mandalorian, but the team definitely knows how to keep a secret, so we may never know until he's in front of us once again. "The fact that we were able to keep my involvement a secret for over a year with no leaks is nothing less than a miracle. A real triumph for spoiler-haters everywhere," said Hamill last year, shortly after the episode debuted.