This is how I have understood the matter, in my own apologetic reflection. Perhaps it will be helpful to others as well:
* * * * *
Because God is Creator He also has the prerogative to judge. This is analogous to our experience. Society takes it upon itself to judge the criminal and punish him if he supercedes the "just" laws that govern the society, in order to prevent chaos and suffering. If that is true of human society (one man to another), it is all the more of God, because He is ontologically above us (Creator and created).
So it is perfectly sensible and moral to posit (apart from the data of revelation) a notion of God judging both individuals and nations. God's omniscience is such that He can determine if an entire nation has gone bad ("beyond repair," so to speak) and should be punished. And He did so. Now, even in a wicked nation there may be individuals who are exceptions to the rule. So some innocent people will be killed. But this is like our human experience as well. In wartime, we go to war against an entire nation. In so doing, even if it is unintentional, some innocent non-combatants will be killed.
But it's also different in God's case because He judged nations in part in order to prevent their idolatry and other sins to infiltrate Jewish (i.e., true) religion. He also judged Israel at various times (lest He be accused of being unfair). In any event, it is not true that nations or individuals were punished because of what their ancestors did. There is a sense of corporate punishment, just described, and it is also true that the entire human race is a fallen race. We all deserve punishment for that fact alone, and God would be perfectly just to wipe us all out the next second. No one could hold it against Him.
He decides to be merciful and grant us grace to do better, but He is under no obligation to do so, anymore than the governor is obliged to pardon convicted criminals. Again, the societal analogy is perfectly apt. If someone rebels at every turn against every societal norm and law and appropriate behavior and so forth, is society to be blamed? Say someone grows up thinking that serial rape is fine and dandy and shouldn't be prevented at all. So he goes and does this. Eventually, the legal system catches up with him and he gets his punishment. He rebelled against what most people think is wrong, and more than deserved his punishment.
We don't say that there should be no punishment. We don't blame society for his suffering in prison. We don't deny that society has a right to judge such persons. So if mere human beings can judge each other, why cannot God judge His creation, and (particularly) those of His creation that have rebelled against Him at every turn? What is so incomprehensible about that? One may not believe it, but there is no radical incoherence or inconsistency or monstrous injustice or immorality in this Christian (and Jewish) viewpoint (which is what is always claimed by the critics).
* * * * *
For further reading, see:
The Destruction of the Amalekites (RationalChristianity.net)
"Shouldn't the butchering of the Amalekite children be considered war crimes?", Glenn Miller
"Why couldn't Israel take in the Amalekites like they did foreign survivors in Deut 20?", Glenn Miller
Genocide in the Old Testament (RationalChristianity.net)
God's moral authority (RationalChristianity.net)
Does God Punish Children for Their Parents' Sins? (RationalChristianity.net)
Does God Show favoritism to the descendants of good people? (RationalChristianity.net)
"God is Wrathful, Vengeful, Jealous, and Angry every day--and you want me to have a relationship with Him?!", Glenn Miller
"How could a God of Love order the massacre/annihilation of the Canaanites?", Glenn Miller
"What about God’s cruelty against the Midianites?", Glenn Miller
"Was God being evil when He killed all the firstborn in Egypt?", Glenn Miller
The Judgment of Nations: Biblical Passages and Commentary, Dave Armstrong
Can God be Blamed for the Nazi Holocaust? Reflections on the "Problem of Evil" and Human Free Will, Dave Armstrong
Supposed Contradiction Between 2 Samuel 24 and 1 Chronicles 21 (God or Satan as Cause?), Dave Armstrong
On the Alleged Contradictions of 2 Samuel 24, and 1 Chronicles 21 and 27 (Dave Armstrong vs. the atheist "DagoodS")
Reply to a Calvinist Critique Concerning the "Hardening of Pharaoh's Heart" (+ Discussion) (Dave Armstrong vs. Colin Smith)
Pacifism vs. "Just War": Biblical & Social Factors, Dave Armstrong
Dialogue on Christian Pacifism and "Just War": Biblical and Social Factors (Dave Armstrong vs. Edward Hamilton)