The Israelis want the Arab civilians out of their target areas, they can't begin their invasion in the way they want to with women and children around. Not that they care about murdering innocents but the optics of using thermobaric munitions in populated areas, especially when clearing tunnels, would be so bad even they couldn't Jew their way out of it.
They targeted the hospital because it's an important service that makes the locals want to stay, especially for families who have sick relatives or who've been injured in the bombings. What's the alternative? The Israelis want the Palestinians to move to a tiny sliver of land in the south with no services, agreeing to this means those sick relatives will likely die a painful death.
Given that these people will not move voluntarily the Israelis have a program to encourage them to move by using small air burst munitions over targets, and they had been doing this with the hospital. Roof knocking is a war crime, but I reckon they took it a step further in this case. Someone got frustrated that it wasn't working and decided to go bigger. Maybe they didn't know there were so many people outside the hospital grounds, more likely they didn't give a fuck. Cue 2 days of non stop cope and propaganda. Jews are gonna Jew.