In Surah al-Kahf, Khidr killed a disbeliever boy so that the boy couldn’t bring sadness to his parents. But isn’t it unfair to kill someone even if he is a disbeliever?
Wa Alaykum al-Salam
Shukran, for your question.
The first point to be emphasized is that Khidr did not take this decision by himself. He killed the individual after Allah commanded him to do so. Allah said in surah al-Kahf,
“So they set out until when they met a boy, al-Khidhr killed him. [Moses] said, “Have you killed a pure soul for other than [having killed] a soul? You have certainly done a deplorable thing” (Qur’an, 18:74). And, “… And I did it not of my own accord. That is the interpretation of that about which you could not have patience” (Qur’an, 18:82).
One may then understand that as how Allah, through His infinite wisdom, may cause an infant to pass away on account of illness; similarly, Allah decreed that this boy should be killed.
Further, Khidr did not kill the boy because he was a disbeliever, as you mentioned. As per Allah’s instruction, he did so to prevent evident harm that he would bring upon his parents. Allah says on the tongue of Khidr, “And as for the boy, his parents were believers, and we feared that he would overburden them by transgression and disbelief.” [Qur’an, 18:80] What this means is that he would have caused his parent to fall into disbelief, in which case they would become from the eternal dwellers of the hellfire.