Excellent question with a good historical answer
Up until the legalization of Christianity in the Roman Empire, Christians who wanted to distinguish themselves sought to be martyred. Depending on who was ruling the Empire or who was the local Roman governor at the time, this could be rather difficult to do. Many Roman officials begged and pled with Christians to pipe down and go home, but persistent Christians refused and presented themselves and their faith to Roman authorities who would ultimately be forced by law to execute them.
After the persecutions were over with the reign of Constantine, martyrdom ceased to be a viable option for demonstrating piety. A pious Egyptian individual named Anthony (now St. Anthony) lived during this time, and pondered how he could possibly deepen his faith now that he couldn’t get himself killed in the name of the Lord. He took to retreats in the desert, and became a hermit. Many people, impressed by his lifestyle and seeking to emulate his piety, took to following him around, and the first “monastic” communities developed around him. The idea was that, now that Christian’s can’t be martyred in the physical sense, they would be “martyred” daily by simply giving up worldly things.
Thus the idea of Christian aestheticism really took hold during this time in the 4th century. An influential bishop at the time, St. Athanasius of Alexandria, wrote an extremely influential book on the life of St. Anthony shortly after his death. Because of the bishop’s influence, the book spread throughout Christendom and monasteries developed everywhere the faith was practiced.
Most of the Catholic religious orders that remain today developed later. The Rule of St. Benedict was developed not too long after in the 6th century, and became the general monastic rule until the high Middle Ages. At that time, the Mendicant Orders (such as the Franciscans, Dominicans, and Augustinians) developed, which blended aspects of monastic life and preaching in the world to suit the needs of that time. These follow the Rule of St. Augustine, which was based on some letters written by St. Augustine himself.
So to answer your question, monasticism in its current form traces its roots to the 4th century. That said, while there are no specific scriptural precedents “monastic communities” as we know them, those in the religious life seek to emulate Jesus’ command to go forth with nothing but the clothes on your back, to place trust fully in the Lord, and St. Paul’s statement that a married man is distracted while an unmarried man can turn his attention totally toward God. These are perfectly good scriptural commands that those in the religious life attempt to carry out to the letter. This makes them particularly holy.
Hope that helped.