Below verse describes what is celibacy (brahmacharya)
कर्मण्या मनसा वाचा सर्ववस्थासु सर्वदा।
सर्वत्र मैथुन त्यागो ब्रह्मचर्यम् प्रचक्षते॥ – यमुनाचार्य
“To always avoid mating in every situation and place by mind, body and speech is celibacy.” Even watching birds or insects or animals mating is also forbidden in brahmacharya.
It seems to me that Gandhi wanted to show the world that he has full control over his mind and senses; such strong control that even when the object of sense enjoyment is close to the body, he is able to maintain full control over his senses. This he did prove.
However, the Hindu dharma scriptures tell the adults to not sleep with any opposite sex adult other than one’s spouse. It is sin to do such a thing. Gandhi obviously did not have a dharma guru for spiritual advice.
jaya sri krishna!