You make it sound like Hamas was passive in this. Baiting your enemy into attacking you in order to galvanize your side still requires them taking the bait. It’s a legitimate strategy, just not a very nice one. See also: US/Japan relations ahead of WW2.