God is the Master of Life. That's exactly why it is within His rights to to take the life of any man, even an innocent one (like commanding the sacrifice of Isaac.) And that's exactly why it is not our right to do so: because we do not possess Divine Sovereignty.
God makes that perfectly clear by the many times God declared the shedding of innocent blood to be abhorrent to Him. (23 times in the verses at the link. Looks like He's trying to make a point.)
He has the right to command it. That is the exception.
He has the right to forbid it. And He does forbid it, forbid it, and forbid it. That is the rule.
They did the same to the city of Ai as well. (Jos8)
Many of the dead would be called “innocent” today. War is not murder.