Joshua (The Story chapter 7) presents two moral dilemmas. First, the text shows God leading his people into war. Second, the directive is to annihilate. Abraham's earlier intercession for Sodom speaks for us, “Will you sweep away the righteous with the wicked?...Far be that from you! Shall not the Judge of all the earth do what is just?” What we learned at Sodom is also what we first learned with Noah: God is a God of justice.
In his 2009 Nobel Prize speech, President Obama defended just war:
We must begin by acknowledging the hard truth: We will not eradicate violent conflict in our lifetimes. There will be times when nations -- acting individually or in concert -- will find the use of force not only necessary but morally justified....To say that force may sometimes be necessary is not a call to cynicism -- it is a recognition of history; the imperfections of man and the limits of reason.
God gave the just cause for war with the Canaanites 400 years earlier when he deeded the land to Abraham. “Your offspring shall come back here in the fourth generation, for the iniquity of the Amorites is not yet complete.” (Gn 15:16) This statement is crucial in portraying the justice of God. God cannot arbitrarily grab land. God acts out of justice. God is also slow to anger, he is going to work with the Canaanites for 400 years before he comes in judgment. While the crimes of the Canaanites are not specifically mentioned, it's safe to assume they are the same sorts of injustices perpetrated by Israel in 2 Kings that brought on their destruction and exile. In Joshua, Israel is less a conqueror than a benefactor of God's judgment upon the inhabitants of the Promised Land.
The second moral dilemma is the divine directive to annihilate. This is far more disturbing because our consciences have been formed by the wider message of the scriptures concerning mercy, justice and compassion. It's not much comfort to observe that almost all wars in the ancient world were conducted by this standard. A close reading of the text does reveal some caveats about this directive;
It was limited in time to only the period of the initial conquest after this it expired.
It was limited in application to include only the area within the defined boundaries of the Promised Land.
For the most part, it never happened as acknowledged by the book of Judges.
Why did God give this directive? It's clear the aim was to remove all temptations to compromise the faith and values of Israel. This could only happen by extinguishing all rival gods and practices at odds with the Ten Commandments. Like a recovering alcoholic purges her household of any and every alcoholic beverage, so Israel was to remove all temptation.
Israel received the directive as a metaphor. The sharp language of the directive was intended to provoke a moral urgency. Jesus used the same technique, “Whoever loves his life loses it, and whoever hates his life in this world will keep it for eternal life.” (Jn 12:25) This pointed language is intentionally discomfiting. Jesus' aim is for us to examine our souls about our life purpose. So Israel understood the directive as a metaphor and applied it to national life for example in King Josiah's reform of breaking down and burning pagan altars (2 Kings) or Ezra's forbidding of mixed marriages (Ezra).
It would be easy to flee to our familiar image of “gentle Jesus, meek and mild.” Yet Jesus makes a final appearance in Revelation as one who “in righteousness judges and makes war.” (Rv 19:11). As God's forbearance of the Canaanites ran out, so the day of judgment will one day come to all the earth. Inequality, injustice, and oppression will not stand. As Rahab sobered up when she heard the armies of Israel were coming, so should we for the armies of heaven are coming. The great patriot, Thomas Paine put it, “I tremble for my country when I remember that God is just.”