I’ve always thought of it as Palpatine let his guard down and revealed his true appearance.
He was physically consumed by evil long before the prequels took place, but he used the force to hide his appearance and appear younger and healthier.
But doing so probably required at least a tiny bit of constant focus. So when he was in his weakest moment, about to be beaten, he lost that focus and his true form emerged.
If only his true form was that of a giant cockroach.