Now before attempting to say something by way of answer to this difficult question, we should do well first to pause and ask ourselves what is at stake here. Suppose we agree that if God (who is perfectly good) exists, He could not have issued such a command. What follows? That Jesus didn’t rise from the dead? That God does not exist? Hardly! So what is the problem supposed to be?
I’ve often heard popularizers raise this issue as a refutation of the moral argument for God’s existence. But that’s plainly incorrect. The claim that God could not have issued such a command doesn’t falsify or undercut either of the two premises in the moral argument as I have defended it:
1. If God does not exist, objective moral values do not exist.
2. Objective moral values do exist.
3. Therefore, God exists.
In fact, insofar as the atheist thinks that God did something morally wrong in commanding the extermination of the Canaanites, he affirms premise (2). So what is the problem supposed to be?
The problem, it seems to me, is that if God could not have issued such a command, then the biblical stories must be false. Either the incidents never really happened but are just Israeli folklore; or else, if they did, then Israel, carried away in a fit of nationalistic fervor, thinking that God was on their side, claimed that God had commanded them to commit these atrocities, when in fact He had not. In other words, this problem is really an objection to biblical inerrancy.
In fact, ironically, many Old Testament critics are sceptical that the events of the conquest of Canaan ever occurred. They take these stories to be part of the legends of the founding of Israel, akin to the myths of Romulus and Remus and the founding of Rome. For such critics the problem of God’s issuing such a command evaporates.
http://www.reasonablefaith.org/site/News2?page=NewsArticle&id=5767
There is much more to this topic here.. it gets into the morality of God issue