That is from the news of the unseen which We reveal to you, [O Muḥammad]. And you were not with them when they cast their pens as to which of them should be responsible for Mary. Nor were you with them when they disputed.
Allah states that the angels spoke to Maryam by His command and told her that He chose her because of her service to Him, because of her modesty, honor, innocence, and conviction. Allah also chose her because of her virtue over the women of the world. At-Tirmidhi recorded that `Ali bin Abi Talib said, "I heard the Messenger of Allah ﷺ say,
(The best woman (in her time) was Maryam, daughter of `Imran, and the best woman (of the Prophet's time) is Khadijah (his wife), daughter of Khuwaylid.)"
The Two Sahihs recorded this Hadith. Ibn Jarir recorded that Abu Musa Al-Ash`ari said that the Messenger of Allah ﷺ said,
This verse presents an argument to prove the prophethood of Sayyidna Muhammad ﷺ by referring to happenings in the lives of Sayyidna Zakariyya (علیہ السلام) and Sayyidah Maryam. These took place in the remote past and there is no likelihood of their being seen or heard or read, specially so, by the Holy Prophet ﷺ which by itself proves that his being so informed of the unknown was beyond the ordinary course of learning. He had just no way of finding out such details by any obvious means at his command. Hence, the truth is that this information was revealed to him as part of the message he gave to others. The text very eloquently states that the Holy Prophet ﷺ was not there to see them drawing lots (by throwing their reed pens in water,. based on prior agreement that the owner of the pen which flows against the current shall be the winner), nor was he present on the scene when they were initially quarreling about the custody of Maryam before agreeing upon the drawing of lots.
The rule governing قُرعَہ Qur'ah (to the drawing of lots) according to Hanafi jurists, is that قُرعَہ Qur'ah (drawing of lots) cannot be given a decisive role in determining the rights known and fixed in Islamic Law. Drawing lots in such a situation is included under Qimar (gambling). For example, if something is jointly owned by several persons and a lot is drawn to decide that the one whose name comes out in the lot shall take the whole thing; or, in the case of a child whose parentage is disputed, a lot is drawn and the one whose name comes out in the lot drawn is taken to be the father. Drawing lots in such cases is not al-lowed in Shari'ah. As for rights which depend upon opinion, قُرعَہ Qur'ah is permissible in them, for instance, while allotting portions of a joint property, A is given the eastern portion and B, the western, by draw-ing a lot. This is permissible because this was permissible even with-out having to draw lots by a mutual agreement of the parties concerned or by a decree of a judge. (Bayan a1-Qur'n)
In other words, it can be said that in a situation where the rights of all parties are equal and the purpose of the lot is only to allocate equal portions to each of them and to decide as to which portion is for whom, then drawing a lot is permissible.
Tazkirul Quran
Maulana Wahiduddin KhanOn ayahs 44–47
God blessed Zachariah (Zakariyya) with an offspring in his old age; provided sustenance to Mary in her shrine; created Jesus without a father, and brought into being chaste and upright people who were descendants of Abraham, so that they could be chosen to communicate the message of God to human beings. God did not grant these blessings to His people for no good reason: He found them so deserving that he showered them with His blessings. These were the people who had no material expectations from their children; their happiness rested upon their children’s dedication and devotion to the cause of God. These were the people who wanted their children to be safe from Satan and join the band of believers. They were not given to jealousy and ill-will on seeing goodness in others. It was through their good influence that their children too were in control of their selves and became one with those who truly remembered God: who chose the right way, abandoning the path that leads one astray. Such are the people whom God provides for out of His special mercy, and who have His special blessings showered upon them.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.