When she was delivered, she said: “O my Lord! Behold! I am delivered of a female child!”- and Allah knew best what she brought forth- “And no wise is the male Like the female. I have named her Mary, and I commend her and her offspring to Thy protection from the Evil One, the Rejected.”
In the religious code of earlier prophets, there was a method of
worship through which a child, out of one’s children, could be freed
from all worldly services and devoted exclusively for Allah. Following
this practice, the mother of Sayyidah Maryam made a vow during her
pregnancy that she would let the newborn serve Baitul-Maqdis in the
way of Allah and that she would not put the child on worldly chores.
Sayyidah Maryam’s mother thought that she will deliver a male child.
But, when she delivered a girl, she was full of remorse thinking that a
girl would not be able to do this duty. But Allah Almighty, out of His
consideration for the sincerity of Sayyidah Maryam’s mother, accepted
that very girl and thereby made her status distinct from any other girl
of the world. (Maariful Quran Vol 2 pg. 63)
Shafi, Muhammad (2008). Maariful Quran. (Vol .2 pg. 63) http://www.islamicweblibrary.com/wp-content/uploads/2020/04/maarif-volum1-english.pdf