The Qur’anic story of al-Khidr and Moses (peace be upon them) is one of the stories which is very difficult to comprehend as it seems against rational and moral principles.
The Qur’an says: And they found a servant from among Our servants to whom We had given mercy from us and had taught him from Us a [special] knowledge (18:65). The verse clearly shows that the servant [al-Khidr] had some special form of knowledge and role. If it were something that could have been known by Moses, then he [Moses] would not have objected to the three actions performed by al-Khidr.
The killing of the youth (ghulaam) as mentioned in verse 18:74 (And so they went on, till they met a youth and he [al-Khidr] slew him...) was objected by prophet Moses as follows: Have you slain an innocent person otherwise than for manslaughter? Certainly you have done an evil thing (18:74).
Some say that the killing of the youth may be likened to the Angel of Death (Izrai’l) taking the life of someone or to cause someone's death by God’s decree and authority. However, the problem with this explanation is that, if the word qatl in the above verse (18:74) is meant to take someone's life without having to kill or slay the person, then prophet Moses would not have affronted al-Khidr because he was aware of that phenomenon (of death). The reason for taking the life of the youth is mentioned in the following verse: And as for the youth, his parents were believers and we feared lest he should make impropriety and disbelief to come upon them (18:80). After giving the interpretation of the three actions that he performed, al-Khidr says to Moses: I did not do it of my own accord (18:82). In other words, he performed the three actions as commanded by God.
Regarding the question as to why God ended the life of the youth before he manifested his impropriety and disbelief, it is based on a false premise that God punished the person for an act before his doing it.
Another exegete, has tried to explain and justify the killing of the youth as follows: al-Khidr has to be an angel because God did not say he is a human being but "a servant from among Our servants". Thus he executed the decree of God to take the life of the youth just like the Angel of Death is responsible to take the life of a person.
Comment: This explanation suffers the same problem as mentioned above, that is, if al-Khidr was an angel, then Moses would not have objected to the killing of the youth. Secondly, numerous traditions from both Sunni and Shia clearly identify al-Khidr as a human servant of God. Some say he was a waliyy and most say that he was a prophet and a messenger of God.
It is interesting to note that according to one exegete, the three acts which al-Khidr performed were all the things that Moses had done or got involved before. First he was thrown into the nile as an infant, yet that was to save him and not to drown him. Then he accidentally killed an Israelite who did not deserve to die. And he also drew water for prophet Shuayb’s daughters without asking any reward. God probably wanted to show Moses that his accusation of al-Khidr could return to him by the same token.
We also read in tafsir al-Mizan the following interesting comment:
Some say that an example of the wonderful politeness shown by al-Khiḍr toward his Lord when speaking—was to attribute those actions not free of fault, to himself, for example, and I wished that I should damage it, and to use the third person plural when referring to what could politely be attributed to himself and his Lord, for example, so we desired, and, and we feared. He also attributed to God alone anything that was exclusive to Him on account of being contingent upon His being Lord (rubūbiyya) and His regulation of His property (tadbīr mulkihi), for example, so your Lord desired that they should attain their maturity.
Conclusion: It is important to realize the nature of this story so that we can adjust our expectations and try not to come up with contrived explanations that are based on everyday situations and experiences.
Reference: al-Mizan, Eng. Vol. 26 (pub. by Tawheed Institute, 2014)