Brahmacharya is first mentioned in the Atharva Veda as a period of time set aside for the study of spiritual topics. In Vedic culture this meant to find the unchanging self inside called Brahman. At this time anyone, male or female, could become a Brahmachari (student) for a period of time dedicated to study and meditation. Celibacy was not required but might be advised by a specific teacher.
By the end of the Upanishads era (about 300 C.E.), Brahmacharya became one of the 4 stages of life (Ashrams). A child was a celibate student until age 25 when one married and became a Grihasta (literally to hold a house) or householder and raised a family. When the Grihasta “looked upon their first grandchild’s face” they were to renounce their home, move into an ashram or forest cottage and live again as a celibate student seeking knowledge and experience of Brahman. This stage was named Vanaprasta (forest dweller). Through this study and practice of renunciation they would grow, over another 25 years, into a very high level of consciousness and become sannyasis, wandering the earth as more spirit than human or physical.
During this same time period, contemplative yoga developed (Patanjali) and Brahmacharya became equated with stepping out of the world in as many ways as possible and reaching for Brahman. World-negating practices were added to Brahman-enhancing practices. Celibacy had sometimes been considered important to help the students focus on their studies. Now it was important because there were no reliable contraception methods and children were considered binding to the world because one became attached to them.
As Tantra philosophy evolved, life energies were seen as powers that could be used in different ways. If sexual energy were not expressed outwardly, it could be used for inner transformation. We see the beginnings of this from Patanjali:
From Brahmacharya power is gained. Yoga Sutra 2.38
Brahmacharya became increasingly tied to celibacy. The idea that sexual energy can be transmuted by control, both restraint of expression and yoga practices such as meditation and pranayama, becomes the foundation for early Hatha Yoga. The sexual energy/fluids (burning poisons that bind the soul) in the pelvis must be sublimated and distilled in the head in the form of nectar that transforms the mind into pure consciousness.
For these energy-transmuting practices, total celibacy was necessary for a period of time. The pressure of these energies needed to build, thus expression or release had to be restrained. Once the process was accomplished and the nectar produced, there is some vagueness as to whether celibacy needed to continue. It makes sense that someone in this state of consciousness would not want to have sex, but, perhaps to illustrate how free they were, some texts indicate that they could have sex and not be bound in any way.
European domination of India in the 18th and 19th centuries suppressed yoga and not much development occurred. As the Indian independence movement began to form, yoga practice was revived as a purely Indian expression of fitness and spirituality. Yoga was taught in Indian schools and was adapted to best educate children. Yamas, Niyamas and Hindu values were expressed strongly as yogic values, and mystical or esoteric concepts were ignored.
Once again Brahmacharya became celibacy during the student years so that one could receive the best education to be successful as a householder later in life.