They were effectively at their wits end.
Israel successfully used Hamas to indefinitely postpone and reject a two-state solution (you can't discuss and/or negociate with tERroriSTs), choking Gaza (reads about the
humanitarian diet) whilst grinding out more and more of the West Bank. The
Abraham Accords signed during the Trump administration effectively meant the disappearance of Palestine as a potential state, in a worldwide indifference, with the Arab countries in the region fully signing on it as a ultimate betrayal. Hamas then went full
Nat Turner style (without the alledged beheadings and mass rapes though, but still with plenty of atrocities) in order to put Palestine on the map again.
Kidnapping is also a kinda misused word. There's ten of thousands of Palestinians, including lots of children, being tortured and rotting in Israeli prisons, with a large majority of them being held without any motive (see
administrative detention). They're as much hostages as the Israeli civilians taken captive by Hamas and a huge deal among the Palestinians, but you'll never see it written as such in Western media. It's always Israeli
hostages vs Palestinian
prisoners (implying that the Palestinians in Israeli prisons automatically did something wrong). Getting those Palestinians free, which only occurs in an exchange with Israeli hostages, earns massive bonus points to whoever gets them free. However the Israeli soldiers that were were captured are POW, not hostages.
At the end of the day, Hamas were cornered with their back to the wall, so they gambled. Massively.
They wanted to unlock the Israeli ever tightening chokehold on Gaza and the West Bank. Given the absolute indifference of the world towards the Palestinian people and its fate, only a massive, bloody operation against the Israeli occupation forces and its civilians would force the world to turn their eyes once again on this region of the world. What would happen afterwards was anyone's guess but it is foolish to think that Hamas didn't count with Israel's response. They cynically banked on it. It might shock many either wet-behind-the-ears greenhorns or blissfull idiots in the West, but it was and still is the M.O. of many resistance groups against an overwhelmingly superior occupation force in a war of independence.
The rest will be History and well beyond Hamas' control. The latter was the smalll stone that lead to an avalanche. Who the avalanche catches is anyone's guess.