You may be underestimating the level of sedition and insubordination of senior military and intelligence people. They have been obsessed with removing Netanyahu, and now it’s easy to see that there were derelict in their military and intelligence duties.
I don't see them as evil or Machiavellian enough to do this. This isn't Russia.
I think Bibi and everyone in the Mossad and the IDF were overconfident and complacent. Hamas got help from Iran and their tactics have evolved.