The matter of punitive severity must be measured against (1) the severity of the offense and (2) the virtue of the one offended. In both cases listed, the punishment was meted against those who had for centuries engaged in the foulest forms of idolatry and had relentlessly abused God’s covenant people—offenses directly leveled at an infinitely holy God.
That the punishment extended to the relatively “innocent” is further no tension in God since (1) culpability for “collateral damage” in war does not necessarily rest with the aggressor, but may rest with the unjust party to war and (2) there are no truly innocent persons in the world.