Given how old and frail pretty much every Pope tends to get at some point, it is surprising how rare it is for them to step down for reasons of bad health. A couple of Papal resignations are known from the middle ages, but none of them had any apparent connection to health. In 1415, Pope Gregory XII resigned in an attempt to end a schism in the church. In 1294, Pope Celestine stepped down after only six months in office, apparently because he didn’t enjoy his new job.
The most interesting case dates from the 11th century. In 1032, a man with the remarkable name Teophylactus of Tusculum was named Pope Benedict IX at the age of only 20. He became one of the most scandalous Popes ever, supposedly holding orgies in the Papal palace on regular occasions. Some sources suggest that he was openly gay.
In 1045, his godfather John Gratian paid Benedict a large sum of money to get him to resign. Benedict agreed and stepped down. But shortly after he changed his mind, returned to Rome with an army and deposed his successor, none other than John Gratian himself (now Pope Gregory VI). Benedict was deposed by the German king Henry III in 1046 but became Pope once again in 1047 after his successor had died. German troops intervened and kicked him out of the Papal palace in 1048, and he was finally excommunicated a year later.