That’s true, you cannot target civilians. But you can destroy a military objective even if you know it will kill civilians. Per ICC:
Under international humanitarian law and the Rome Statute, the death of civilians during an armed conflict, no matter how grave and regrettable, does not in itself constitute a war crime. International humanitarian law and the Rome Statute permit belligerents to carry out proportionate attacks against military objectives, even when it is known that some civilian deaths or injuries will occur.
“Eliminate every human” is not a valid objective, but “eliminate Hamas” is.