Right graciously did her Lord accept her: He made her grow in purity and beauty: To the care of Zakariya was she assigned. Every time that he entered (Her) chamber to see her, He found her supplied with sustenance. He said: “O Mary! Whence (comes) this to you?” She said: “From Allah: for Allah Provides sustenance to whom He pleases without measure.”
In order to fulfil her vow, Sayyidah Maryam’s mother took her to
the Mosque of Baitul-Maqdis and talked to the care-takers and worshippers at the Mosque, Sayyidna Zakariyya being one of them, and
told them that she had vowed to dedicate the child in the service of
God and therefore, she could not keep the child with her. She asked
them to take her and keep her.
Sayyidna ‘Imran was the Imam of this Mosque. He had died during
the pregnancy of Maryam’s mother, otherwise he would have been the
most deserving person to have taken charge of the child, being the
father and the Imam of the Mosque. Therefore, every keeper and
worshipper of the Mosque wished to take her in his custody. Sayyidna
Zakariyya pleaded his bid for custody by saying that his wife was
Maryam’s aunt and she being next to her mother certainly deserved to
keep her. But, people did not agree to prefer him over the others.
Finally, everybody agreed to draw lots, which turned out to be fairly
strange as it would appear later. Here too, it was Sayyidna Zakariyya
(pbuh) who turned out to be the winner.
So, he got custody of Maryam. According to some reports, he employed a wet-nurse to have her suckled. Other reports say that she
just did not need to be suckled. She grew up able to sit and walk and
Sayyidna Zakariyya (pbuh) put her in a good house adjacent to the
Mosque. When he went out, he locked the house and opened it on return. This has been stated briefly in the present verse. (Maariful Quran vol 2 pg. 38)
Shafi, Muhammad (2008). Maariful Quran. (Vol .2 pg. 38) http://www.islamicweblibrary.com/wp-content/uploads/2020/04/maarif-volum1-english.pdf