Was al-khidr killing the child unfair

No it wasn’t unfair. Al Khidr had orders from Allah to take his life. Since Allah is the owner of life and death he can kill whoever he wants whenever he wants. Allah is not held to any moral accountability we humans are. If we read the Quran there was a specific reason as to why the boy’s life was taken: ”And as for the boy, his parents were believers, and we feared that he would overburden them by transgression and disbelief. So we intended that their Lord should substitute for them one better than him in purity and nearer to mercy.” (Quran 18:80-81) Plus if the boy hadn’t reached puberty and Allah decided to take his life then the boy would go to heaven since children who die before puberty go there. https://sunnah.com/bukhari:7047