I think, Prophet Zakariya's guardianship inculcated some outstanding qualities into Mary.
3:37 Her Lord accepted her graciously. (Mary was dedicated to the temple) and He made her grow in purity and elegance, a gracious upbringing, under the guardianship of Zakariya (Zacharias). Whenever he entered the chamber of Mary, he found that she had food. (Knowingly) he asked, “O Mary! Where does this food come from?” She said, “It is from God.” God provides according to His Laws, beyond reckoning.
[Zakariya was a Prophet of God and a distant uncle of Mary. ‘It is from God’… Visitors to the sanctuary serve the saints. Many of them bring gifts to get their vows fulfilled. Yasha in reference to God = Through His Laws = Common mistranslation, ‘as He pleases’. Bighayiri hisaab = Beyond reckoning = Without account = Humans cannot reckon God’s Power of sustaining and providing the entire Universe. The last sentence of the verse cannot be a quote from Mary, as generally suggested, since she would not lecture a Prophet of God](Zacharias).