(Then they both proceeded,) means, after the first incident,
حَتَّى إِذَا لَقِيَا غُلاَمًا فَقَتَلَهُ
(till they met a boy, and he (Khidr) killed him.) It has been stated previously that this boy was playing with other boys in one of the towns, and that Al-Khidr deliberately singled him out. He was the finest and most handsome of them all, and Al-Khidr killed him. When Musa, peace be upon him, saw that he denounced him even more fervently than in the first case, and said hastily:
أَقَتَلْتَ نَفْسًا زَكِيَّةً
(Have you killed an innocent person) meaning, a young person who had not yet committed any sin or done anything wrong, yet you killed him
We now move to the sentence: حَتَّىٰ إِذَا لَقِيَا غُلَامًا (until when they met a boy -74). The word: غُلَام (ghulam) in the text is used for a minor boy in the Arabic usage. This boy killed by al-Khadir (علیہ السلام) was a minor - as corroborated by Sayyidna Ibn ` Abbas ؓ and most commentators. Further on, when the words: نَفْسًا زَكِيَّةً (innocent person) were used for him, that too supports the view that he was a minor. The reason is that زَكِيَّةً (zakiyyah) means 'free of sin' and it can be either the attribute of a prophet or a minor child who faces no accounting for what is done by him and no sin is written in his Book of Deeds.
Tazkirul Quran
Maulana Wahiduddin KhanOn ayahs 74–77
Damaging a good boat and killing a child do not appear to be good deeds. But, as the ensuing verses show, a profound sagacity was hidden in them. These apparently wrong deeds were in reality correct and useful acts. This also provides an answer to what is known as the ‘problem of evil’. In this world of human beings, there are many things which at first sight appear to be evils in the system. Yet, they are based on deep wisdom. It is true that in the present world this wisdom is hidden behind a veil. But, in the life hereafter, this veil will not be there. At that time, man will come to know that whatever happened was done according to the highest standards of justice.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.