Ideally Israel wouldn’t have been oppressing Palestinians in the first place so that Hamas would never have come to power. They could have engaged in dialogue and diplomacy with Hamas and the Palestinians to figure out something that would work for everyone. They could have negotiated a prisoner swap or something for the hostages.
But Israel, specifically Likud and the right-wing parties, have no interest in this. They want all of Palestine gone, and to control it all themselves.