Imagine you are a parent whose child was killed in the fighting between the two warring sides. Both sides claim that they were defending themselves against the aggressor, and although their intention was not to kill your child, his death was, according to them, an unavoidable consequence of their self-defense. Therefore, they claim, they are not morally or legally liable for the death of your child.
What would you say to them? Would you accept their justification? I don't think I would be satisfied with their justification because I don't think it is my child's duty to die for the sake of someone else's self defense. Neither I nor my child ever agreed to a contract in which we would accept paying with our lives for someone else's safety.
This is recognized by law in most jurisdictions. If you killed an innocent bystander while defending yourself in the US, your action would be labeled as reckless injury of a third person. For example, Sec. 9.05. of the Texas Penal Code states:
"Even though an actor is justified under this chapter in threatening or using force or deadly force against another, if in doing so he also recklessly injures or kills an innocent third person, the justification afforded by this chapter is unavailable in a prosecution for the reckless injury or killing of the innocent third person."
One might argue that the definition of a reckless injury of an innocent third person does not apply in the Israel-Hamas conflict--i.e., that the injury or death was an unavoidable consequence of necessary self defense. This is fine, but this claim is a matter of a legal dispute in court. I doubt that any of the parents of the children killed in the Israel-Hamas conflict will ever get the chance to accuse anyone, in the court of law, for the death of their children. This is tragic and sad.
So, the least we can do is to refuse using war as an excuse for abandoning the rule of law. The fact that an innocent person was killed during a war doesn't make that person any less dead than an innocent person killed in peace time.