The problem is that Israel and Hezbollah are currently in a state of informal hostilities but are not in a state of declared war. That distinction matters at the international level.
In the case of Gaza, Israel and Hamas were in a truce, until Hamas unilaterally broke that truce on October 7, 2023. It turns out Hamas had been using the most recent truce to build up its forces and plan those terrorist attacks, which is why Israel is unwilling to enter into a new truce. (And on a historical note, Hamas has unilaterally broken or violated every truce and peace treaty it has negotiated with Israel.) Given that the Gazan civilian population was openly sheltering and supporting the Hamas forces, the international rules of war hold that Gazan civilians are legitimate collateral damage so long as there was no intent by Israel to deliberately attack civilian targets. Importantly, Israel is formally at war with Hamas, so the legal framework is different from what happened with Hezbollah.