Ben Solo goes after her, and convinces Palpatine to let Rey live, by allowing Palpatine’s spirit to possess him. As this happens what remains of Ben tells Rey, that it will only be a matter of time before he is consumed, and she should kill him. She does, and Palpatine’s spirit tries to get back to the clone body, but Rey destroys it before he can enter the clone. Being without a vessel for his spirit, the Force ghosts of the Jedi appear, and destroy Palpatine’s spirit.
IIRC this was a pretty popular rumor before the movie came out? Something like this. I know at the least a few people thought the redemption/sacrifice Ben was going to make in the movie was along these lines.
I remember so many people also just kind of automatically assuming there were going to be a ton of force ghosts in the climax once Palpatine got announced. It just seemed to follow that if you were bringing back a long dead bad guy you now had the door open to ALSO bring back all the long dead good guys as a counter.