score:7
Popes who were legally married either as Pope or before they became clergy and were in fact widowed at the time of their election as Supreme Pontiff are as follows:
St. Peter (30/33-64/67) Mother-in-law is mentioned in the Gospel verses Matthew 8:14–15, Luke 4:38, Mark 1:29–31 and who was healed by Jesus at her home in Capernaum. 1 Cor. 9:5 asks whether others have the right to be accompanied by Christian wives as does "Cephas" (Peter). Clement of Alexandria wrote: "When the blessed Peter saw his own wife led out to die, he rejoiced because of her summons and her return home, and called to her very encouragingly and comfortingly, addressing her by name, and saying, 'Remember the Lord.' Such was the marriage of the blessed, and their perfect disposition toward those dearest to them.”
Pope Felix III (483–492) Married and widowed before he was elected as pope.
Pope Hormisdas (514–523) Married and widowed before he took Holy Orders.
Pope Adrian II (867–872) Married to Stephania before he took Holy Orders,[9] she was still living when he was elected Pope and resided with him in the Lateran Palace
Pope John XVII (1003) Married before his election as Pope.
Pope Clement IV (1265–1268) Married before taking holy orders.
Pope Honorius IV (1285–1287) Married before he took Holy Orders, widowed before entered the clergy.
The last pope to be married and pope at the same time was Pope John XVII (1003). In 1075, Pope Gregory VII made celibacy mandatory in the Latin Rite.
From 1075 and on no individual could become pope while still married. If a pope remained true to his vow of celibacy that is another matter.
In 1075 Pope Gregory VII issued a decree effectively barring married priests from ministry, a discipline formalized by the First Lateran Council in 1123. Since then celibacy has been required of Roman Catholic priests, though the Catholic churches of the East have continued to allow priests to marry before their ordination. - Why are priests celibate?
Widowers have always been permitted to become priests and bishops.
Upvote:6
You mention both marriage and celibacy in your question. Since "celibate" means abstaining from marriage and sexual relations:
The last documented pope who was married was Pope Honorius IV (1285–1287), married before he took Holy Orders, widowed before entered the clergy.
The last documented pope who had sexual relations after receiving holy orders was Pope Leo XII (1823–1829), as nuncio in Germany fathered three illegitimate children.
The last documented pope who had sexual relations with women during pontificate was Pope Alexander VI (1492–1503), ad a long affair with Vannozza dei Cattanei while still a priest, but before he became pope; and by her had his illegitimate children Cesare Borgia, Giovanni Borgia, Gioffre Borgia, and Lucrezia. A later mistress, Giulia Farnese, was the sister of Alessandro Farnese, and she gave birth to a daughter (Laura) while Alexander was in his 60s and reigning as pope.[41] Alexander fathered at least seven, and possibly as many as ten illegitimate children, and did much to promote his family's interests – using his offspring to build alliances with a number of important dynasties.[42] He appointed Giovanni Borgia as Captain General of the Church, and made Cesare a Cardinal of the Church – also creating independent duchies for each of them out of papal lands.
The last documented pope who had sexual relations with men was Pope Julius III (1550–1555), The Venetian ambassador at that time reported that Innocenzo shared the pope's bed.
The last documented pope who had sexual relations with men and women was Pope Benedict IX (1032– became pope in 1044, again in 1045 and finally 1047–1048). Accused by Bishop Benno of Piacenza of "many vile adulteries." Pope Victor III referred in his third book of Dialogues to "his rapes... and other unspeakable acts." His life prompted Peter Damian to write an extended treatise against illicit sex in general, and h*m*sexuality in particular. In his Liber Gomorrhianus, Damian accused Benedict IX of routine sodomy and be*t**lity and sponsoring orgies. In May 1045, Benedict IX resigned his office to get married.
The full historical list of popes who were married before holy orders, or violated celibacy can be found here.