Celibacy or Brahmacharya is the act of refraining from sexual relations/desires and marriage. Earlier at the time when it was preached and talked in favor of, it was not taken quite well. The culture did not see the point of it when one cannot reproduce, have a family to love and a extend one's legacy to the next generation. As it is very clear from the Vedas that there are many ways to reach the fulfillment of desires but reaching a state of salvation is straight but not that easy as it sounds. Like worshipping in various ways (Bhakti) as per the different temperaments is the prerequisite to meditation, similarly, Katha Upanishad advocates practicing Brahmacarya to reach the World of Brahma and thus attain salvation.
"Atha yad yajna ity acaksate brahmacaryam eva tat, brahmacaryena hy eva yo jnata tam vindate atha yad istam ity acaksate brahmacaryam eva tat, brahmacaryena hy evastvatmanam anuvindate." Taken from Chandogya Upanishad, Chapter VII, Section 5, it says that what people think and call sacrifice is actually the disciplined life of a student of sacred knowledge. One who really wants to attain that level of spiritual gain has to be free from desires.
"Atha ya sattryanam ity acaksate brahmacaryan eva tat, brahmacaryena hy eva sata atmanas tranam vindate. atha yan maunam ity acaksate brahmacaryam eva tat, brahmacaryena hy evatmanam anuvidya manute." Taken from the same Upanishad, this Shloka tells us that what people call 'Protracted Sacrifice' (Sattrayanam) is really the disciplined life of a student of sacred knowledge. And only by this means one can protect the real self. Also, what people call the vow of silence is too a way of discipline with the help of which one does really meditate towards salvation.
The above sections from the Vedas tell us how important it was considered for a student of Vedanta to follow Brahmacharya. In Vedic culture, it was suggested and preached to be followed in the later life after you have lived your part of life to the fullest of your desires. So these two periods were considered crucial for the soul to attain the knowledge. But there are a number of yogis in the history of Hinduism who have practiced brahmacharya throughout their life. Swami Vivekanand was one of the strongest advocates of Celibacy. He even owed his photographic memory to the same virtue.
Not only Hinduism but other religions of the world talk in favor of celibacy as a part of devotion towards the Supreme believing that without this enlightenment cannot be attained. Buddhism and Jainism preach celibacy to be practiced even by the young monks. Buddha never restricted people from involving themselves sexually but his thoughts on celibacy were quite clear.
The sexual activity is a part of the craving for sensuality. The activity itself is less obstructive to the path of liberation than the thoughts of desire we generate around it. Another meaning of Brahmacharya is to walk and behave in a divine way. The sensual attachment is a hindrance to meditation and realizing divinity.
There is always a path to meet one's personal desires but to be in unity with God and release oneself from the cycle of life and death, there is a course of action which will pass through non-attachment to worldy gains and devotion towards spiritual gains.