In verse 81, it was said: فَأَرَدْنَا أَن يُبْدِلَهُمَا رَبُّهُمَا خَيْرًا مِّنْهُ زَكَاةً وَأَقْرَبَ رُحْمًا " We, therefore, wished that their Lord would replace him with someone better than him in piety [ having good deeds and morals ] and more akin to affection [ fulfilling due rights of the parents ]."
It will be noticed that the form used in this situation is plural: خَشِينَا (we apprehended) and: أَرَدْنَا (we wished). One reason for it could be that al Khadir (علیہ السلام) attributed this apprehension and wish to himself and to Allah Ta` ala both. And it is also possible that he may have attributed it to himself alone - if so, the expression: أَرَدْنَا (we wished) would mean: 'we prayed to Allah' because this matter of replacing a boy with a better one is an act which falls in the exclusive domain of Allah Ta` ala. Al-Khadir (علیہ السلام) or some other human being cannot be associated with it.
If, at this point, someone were to say: If it was in the knowledge of Allah Ta’ ala that this boy will grow into an infidel and mislead his parents as well, then, this event - true to the knowledge of Allah Ta` ala - should have necessarily transpired as it did. Then this doubt would be incorrect for the reason that nothing can come into being contrary to Divine knowledge.
It can be answered by saying that it was there in Divine knowledge with the appendage and condition: If he reached maturity, he will not only become a disbeliever himself but would pose a danger for other Muslims also. Then, as he was killed before reaching the age of maturity, the ensuing event is not contrary to Divine Knowledge. (Mazhari)
Ibn Abi Shaibah, Ibn al-Mundhir and Ibn Abi Hatim have reported from Ibn ` Atiyyah that Allah Ta` ala had blessed the parents of the slain boy with a girl in his place who became the mother of a prophet. And, as in a report from Sayyidna Ibn ` Abbas ؓ she gave birth to two prophets. Some other reports say that through the prophet she gave birth to, Allah Ta` ala gave guidance to a large community.