Mohandas Gandhi’s relationship to Hindu notions of sex and sexuality has been the subject of much debate. The answer to the question depends on the angle and the segment of Hindu sex and sexuality under consideration. For instance, Hinduism allows men to remain celibate for their entire lives. Celibacy was stressed by Gandhi because he saw it as a means to build his willpower and test his self-control.
Gandhi’s emphasis on celibacy could be seen as drawing on Hindu notions of sex and sexuality and resisting them. He draws on the notion that some men—particularly those mainly concerned with spiritual matters—will want to abstain from sex altogether. In a different light, one could make the argument that he resists the Hindu notion that sex is permissible and not automatically deleterious to a person’s spiritual aims.
In a way, Gandhi’s non-indulgent approach to sex and sexuality connects to certain conservative Christian and Jewish views about sex and sexuality. Some traditional Christians and Jews believe certain kinds of sex poses a threat to one’s spiritual relationship with God. For them, sex should only take place between married people. While pleasure isn't irrelevant, procreation tends to be the main goal.
These limited views of sex might be a good starting point to think about why homosexuality remains one of the biggest battlegrounds in religions. If the primary purpose of marriage and sex is to create children, then same-sex partnerships inevitably pose a problem.
Conversely, one might think about how homosexuality is becoming less of a battleground for religions today. Pope Francis has expressed support for LGBTQ+ persons. Meanwhile, Israel, the self-proclaimed homeland of the Jewish people, has tried to adopt a more inclusive stance towards LGBTQ+ persons.