This is the classic dilemma of urban warfare. Armies are designed to fight other armies, where their targets are tanks, and artillery, and battalions of soldiers. Urban warfare is the most deadly form of warfare, because you have to go door to door, room to room, not knowing who's friend and who's foe until they start shooting.
To minimize their own causalities, requires they not take chances. If a sniper fires from an apartment building filled with civilians, you take out the apartment building. If someone fires a mortar from a school filled with children, you take out the school.
Which is why the Geneva conventions prohibit fighting a war that way.