But that’s not really what happened and is happening here.
Yes, Hamas was initially elected by the people of Gaza. But then they effectively eliminated any further meaningful elections. So there was no real way to get rid of them short of civil war - which Hamas made sure to make very difficult.
To use your simile, its more like inviting a neighbor over for dinner, then having them take you hostage and start using your house as a base for their crime spree. Then the police show up and burn down your house with you in it. Now your family and friends hate both the bully neighbors AND the police.
I don’t think ordinary Gazans have all that much love for Hamas. But to cooperate with anyone in identifying Hamas members puts a target on their backs for other Hamas members to take revenge.
I think that blaming Gazans as being part of the problem is much too short sighted.
If you invite the Hells Angels into your house for Dinner you deserve what you get. That is the correct simile since everyone knew that Hamas was a terrorist organization. You can rationalize it away but in truth, if your neighbors are terrorists, either you are in the wrong neighborhood or you need to start cleaning it up ASAP.