According to tradition, the mother of our Lord was educated at the Temple of Jerusalem when she was a child. (That’s tradition with a small ‘t’ — not infallible Sacred Tradition, but a human tradition.) The priests of the Temple of Jerusalem were male only, and only the priests were permitted to enter the inner areas of the Temple. But there were many buildings associated with the Temple itself, and devout Jewish men and women could enter certain areas. The Temple was the center of worship in the Jewish Faith during the time of the lives of the Blessed Virgin Mary and her Divine Son Jesus. Jews traveled there from all over the world, especially for the three great feasts: the feast of Tabernacles, the feast of Passover, and the feast of Weeks (Pentecost).
Blessed Anne Catherine Emmerich gives quite a few details of Mary’s time in the Temple of Jerusalem, in her book The Life of the Blessed Virgin Mary. According to that account, a group of young girls served at the Temple, referred to as the Temple Virgins. They were educated and guided by a group of older women, widows who were once Temple Virgins themselves.
The typical age at which a girl became a Temple Virgin was what we call school age, about 5 to 7 years old. But I discern from the writings of Blessed Anne Catherine Emmerich that the Blessed Virgin Mary was about three years and three months old counting from birth, or almost exactly 4 years old from her Immaculate Conception, when she entered the service of the Temple. Mary was very advanced in understanding for her age, because her mind and heart were not clouded by original sin and concupiscence. She did not have the Beatific Vision, nor did she know all things. But she could not be mistaken about whatever she did know. For her mind and heart were perfectly clear, and her soul was perfectly enlightened by grace.
The Temple Virgins were very well educated. They were taught to read and write, during a time when most adult men were illiterate or barely literate. An adult man in those days might be considered to be literate, and truly be admired by his neighbors for his literacy, if he could read and write at what we could consider to be a grade school or middle school level. But the Temple Virgins, from a young age, could read and write better than most literate adult men, perhaps at a high school level.
The women who taught the Temple Virgins were themselves well educated. They were once Temple Virgins themselves. They had the guidance and instruction of the Jewish priests. So all the women and girls were well taught in matters of religion. They could read and write Hebrew (and probably some Aramaic). They knew the Scriptures well, and they had a good understanding of the doctrines and disciplines of the Jewish Faith.
But you should not imagine that the Temple priests were only well educated in matters of religion. In those days — in Jewish, Roman, and Greek societies — there was not so much specialization of study and knowledge as there is today. Every well educated person was expected to know every subject. Yes, every subject: religion, math, astronomy, botany, medicine, and more. Pliny the Elder wrote a book in the first century A.D., called Natural History, in which he summaries the knowledge of scholars at that time in a wide range of fields.
So the Jewish priests were not only schooled in religion. They understood mathematics and astronomy, so well that they could determine the start of the lunar cycle. And like the Roman and Greek scholars, they likely could calculate the dates when eclipses would occur. Also, despite the common misconception that people thought the world was flat until Columbus proved otherwise, Pliny the Elder states that Greek scholars first determined that the world was round about the six century B.C.
The Jewish priests also had knowledge of botany, medicine, and other fields of knowledge. There were the best educated scholars in Jewish society. As a result, the Temple Virgins had the best education available to Jewish girls at that time, and probably a better education than was given to girls in Greek and Roman society, even within wealthy families. Moses growing up as the adopted child of the Pharaoh had no better education than these girls.
So the Blessed Virgin Mary was very well educated. And since she was sinless and filled with grace, she took in her lessons much better than any of the attentive and studious girls her age.
The girls were chosen to enter the service of the Temple if they and their family were devout Jews. The widows who taught the girls at the Temple were former Temple Virgins, but they also were required to have lived holy lives since departing from the Temple at the end of their service. The girls completed their service about the age of 14 years, so that they could rejoin their families and then be married shortly thereafter.
Now the Temple Virgins (other than Mary) were not vowed to be virgins their whole lives. “Upon reaching a certain age, they were given in marriage, for there was among the more enlightened Israelites the pious, though secret hope that from such a virgin dedicated to God, the Messiah would be born.”  (cf. Isaiah 7:14). Blessed Anne Catherine also tells us that the Virgin Mary left the Temple to be given in marriage to Joseph at the age of 14 years. “When the Blessed Virgin had reached the age of fourteen and was to be dismissed from the Temple with seven other maidens to be married….”  Thus, the age of marriage for the Temple virgins was generally 14 years or so. 
So when Matthew and Luke each wrote about Mary, referring to her as a virgin (Mt 1:23; Lk 1:27), the meaning of the term probably included the knowledge and assertion that Mary was a Temple Virgin.
 Emmerich, The Life of Jesus Christ and Biblical Revelations, Vol. 1, p. 177.
 Emmerich, The Life of the Blessed Virgin Mary, p. 129.
 Apocryphal literature claims that the virgins were dismissed so as not to defile the Temple once they reached menarche. Proto-evangelium of James, 8.2. The women who taught the virgins were older widows, and so were post-menopausal.