I always thought that was one reason that men became priests in the Catholic church. If you were gay, you couldn't shack up according to the church, and you would be expected to marry. What was the best way out? Become a priest, then you don't have to marry without others questioning you.
I think a lot of people get deeply into religion because of skeletons in their closets trying to either get over them or hide them better.