Hamas was the democratically elected government of Gaza. Just remember that.
And they were supported by Israel
https://www.timesofisrael.com/for-years-netanyahu-propped-up-hamas-now-its-blown-up-in-our-faces/