Let me quote a phrase from Atharva veda
Karmanaa manachaa vaachaa sarvaavastu sarvadaa
Sarvatra maidyatvyahu brahmacharyam prachakshyadet
This is the vow of Brahmacharya every Brahmin has to take during his sacred thread ceremony. What does this mean?
What it means is that the subject (male) pledges to have complete abstinence from sexual action and sexual thoughts. The subject pledges that self control and reliance is his weapon towards “bodily distractions” and he will use his energy to focus on his studies, not bodily pleasures.
This is the phase when the scholar is discovering the depths of his mind. He will enter “Grihastha” phase after he has discovered his ability and hence, sexual desires should be abandoned during “Brahmacharya”.
There is another thing called “Akhanda Brahmacharya” wherein the subject pledges not to see the face of any woman, neither touch or sense her in any way and pledges for lifelong celibacy, this is done to obtain complete sexual abstinence for bigger and broader things. Swami Vivekananda attributed his success and magnificent personality to his perfect observance of brahmacharya.
Masturbation is discouraged is because this act leads to nothing. It’s just a way to calm down the energy that is produced inside the body and the result is nothing but loss of energy, produced inside the Jathagrni (Shukra).
Loss of semen causes cowardice, scattered intelligence and severely damages the thinking capacities of a man. A celibate man will have a different dimension of thinking, compared to a man who participates in unnecessary loss of semen. Yes, the loss of semen seems gratifying for a moment but it is not the solution, since the subject becomes a slave of his own desires.
A quote from Bhagvad Gita
Rajo Ragatmakain viddhi trisna sanga samudbhavam
Tan Nibadhmati Kounteya Karma sangena dehinam
Hey son of Kunti. Know that lust has no end and the modes of passion is what causes attachment and enslaves the mind. This causes sentimental infatuation which suppresses consciousness and the man never knows his true potential. This is “Maya” and all “Maya” has a beginning and an end and hence, the wise men do not waste their time on them.
As far as women are concerned, this does not affect them to the extent it affect a man. It is because they lose their energy on a periodic basis anyway and there is no way they can retain it. A man has the ability to retain his energies inside and hence it is discouraged.
Read this: The Imortance of Brahmacharya! (by Sri Swami Sivananda)