As it turns out, Emperor Palpatine had already sensed the "flickering light" in Darth Vader long ago. That's why he has been preparing for his eventual death for years. When Anakin threw him into the Death Star's shaft, he thrust his consciousness far, far away into the body of his clone, Exegol. Unfortunately for him, the transfer was imperfect 'cause the clone body that he used wasn't ideal for his power. Looking back, this adds a whole new meaning to the ending of the sequels. When everyone thought they'd already won, the biggest threat was already planning his next move.