There are several angles to this.
- In recent weeks, Iran's three biggest enemies (US, Saudi, and Israel) have been working on a long term peace deal between the Saudis and Israelis. Given the reports that last weekend's terror operation was allegedly planned for two years, its timing seems more coincidental than anything, but the long term ramifications obviously work out in favor of the Iranians (who fund and train Hamas).
- The Hamas leadership are probably somewhat surprised at how well things went and that they were able to easily overwhelm, murder, and kidnap at will in the initial hours. That said, I think the Hamas goal would've been to take as many hostages as possible and use them as bargaining chips to negotiate the release of Palestinian hostages, gain political concessions from the Israelis, reorient global attention back to the middle east (and away from Ukraine), and as a bonus, kill any Israeli momentum towards bilateral peace deals with other Arab countries.
- Things however seem to have gone wrong for Hamas leadership in that they did not factor in the likelihood that the attack would galvanize Israel to actually invade Gaza to disarm and entirely remove Hamas, and subsequently reoccupy Gaza to prevent any further militant activity from ever being able to harm them.
This is why it feels like a ground war followed by a lengthy counterinsurgency campaign is inevitable, which given the amount of people in such a small area, would likely go on for weeks and months. Heavy civilian casualties will ensue.