There was a lot of hype surrounding the return of Emperor Palpatine heading into the release of Star Wars: The Rise of Skywalker back in 2019, but the final product that hit theaters did nothing but create confusion regarding the iconic villain's comeback. It was revealed that Palpatine was actually Rey's grandfather, and he somehow spent decades cloning himself and building an enormous fleet of ships on the remote planet of Exegol, despite dying at the hands of Darth Vader.
The events surrounding Palpatine's left a lot to the imagination, but Lucasfilm Story Group member Emily Shkoukani is helping make sense of it all with a new edition of Star Wars Inside Intel. In a new piece on StarWars.com, Shkoukani went into detail about how the evil Emperor came back to life, and what happened to the villain in the years between Return of the Jedi and Rise of Skywalker.
Everything about Palpatine's return hinges on something called the Contingency, which was mentioned in books like Star Wars: Lost Stars and Star Wars: Aftermath. Long story short, Palpatine was concerned about his own death and wanted to outlive his mortality. So he created the Contingency, which consisted of a chain reaction of different events that would take place if he were killed.
There are a lot of details about the Contingency that have to do with the fall of the Empire and Operation: Cinder, but they don't address the "how" of Palpatine's survival as much as they deal with the construction of the First Order. For the actual resurrection, it all comes together on the Sith planet of Exegol, where Palpatine spent a lot of time before his death.
Palpatine and his Sith Eternal cult experimented with cloning on Exegol and spent years putting together the Final Order fleet. It was always Palpatine's plan to have this ready-made army waiting for him when he returned after his death. When Vader killed him on the second Death Star, Palpatine's consciousness was transferred to a clone of his own body on Exegol. The body was too weak for him to really use, which lead to him creating strand-casts of himself. These experiments were designed to find the perfect vessel for Palpatine to once again conquer the galaxy.
These clone versions of Palpatine led to Rey, as one of them went on to have a daughter. The experiments also created Snoke, who ran the First Order in Palpatine's stead. When Palpatine found out about Rey, he knew that she would be the most powerful vessel for him to commandeer, so he used his clones and resources to try and draw her to him.
So, to make a long story short, Palpatine always knew he would die, and he spent years building failed clones of himself in order to one day rule the galaxy again.