In Chapter 11 of MacCulloch’s book he wrote about how clerical celibacy became mandatory (mostly due to fears of land ownership by the Church).
Here’s some additional material about other possible reasons for clerical celibacy and homosexuality in this article: