Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) narrates its explanation from the Companions: Concerning the story of Maryam: those people who used to write the Torah, when a person was brought to them, would test him by drawing lots over him to decide who would teach him. Sayyiduna Zakariyya (peace be upon him) was the most virtuous of them and was also a prophet, and the sister of Maryam was married to him. When they brought her, Sayyiduna Zakariyya (peace be upon him) said: "I am more entitled than you, because her sister is married to me." But they still refused, so they went to the River Jordan and cast into the river the pens with which they used to write the Torah, (to decide) who would take charge of her. The pens were carried along by the current, but the pen of Sayyiduna Zakariyya (peace be upon him) stood upright on its tip as though it were in mud, so Sayyiduna Zakariyya (peace be upon him) took the girl.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب العتق / 21402