They know that firing these rockets will only hurt their situation, and they don't care. But what can you expect from organizations that endorse suicide attacks on civilians.
It actually massively helps the organization. Hamas was suffering with a possible uprising not that long ago, and this will only reinforce people to stand in circle around the flag. Now this doesn’t help the inhabitants, but we all know that they don’t care. Casualties will be in place, but the situation will allow for a few deaths on the Israeli side that counts as a win to the PR spinners at Hamas’s disposal.
I do hope Gazans can see through this and continue rioting for more effective leadership; like the Democratic Front or PFLP(-GC), that are more localized and people first than the rigid Islamic internationalists trash that caused Gaza’s economy to collapse in the first place.