"Christians believe that God is good, and yet why did God order the slaughter of all Canaanites? Isn't that a contradiction? Isn't killing the Canaanites a violation of God's own Law in the Ten Commandments?"
This is a very hard question indeed. This is one of those intellectual gauntlets through which modern day Christians must ride in countless college dorm room discussions or at cocktail parties. Non-Christians are fond of bringing up this question (along with mentioning the nasty episodes of the Crusades or the Spanish Inquisition, or the "problem of suffering"). God's command here sounds very harsh to modern ears. It sounds like genocide, or the Nazi "final solution", or "ethnic cleansing", all things for which modern day leaders would face war crimes tribunals. On the face of it, the Hebrew God would seem to be downright monstrous!
This could be approached in a variety of ways. I offer some ideas below, but I will be honest enough to admit that I don't think I know the full story. This is a problem for me also, and I feel a strong affinity for you as you struggle to understand this. I have no illusions as to my amazing erudition on this topic, but I'll attempt to address this.
One approach would be to say, "well, that was the Old Testament; now we're in a new era which is all about Jesus and love, so let's all just hold hands and sing..." (Cue the psychedelic music). By the way, I have seen that approach in action, but it is wrong. It is wrong because the Old Testament is more than a mere footnote to the New Testament. It is wrong because God is "the same yesterday, today, and forever." If you would embrace Jesus, you must also accept the Old Testament along with the New. Because Jesus did so.
1. It was a righteous judgement. And P.S. We all have it coming
Part of the answer is that the concept of "goodness" also entails the biblical concept of "holiness". To be perfectly good means to be so set apart from evil and corruption as to be unable to abide it. Holiness (and goodness) can't coexist with corruption. And humans are corrupt. God says "be holy" and we can't do it.
The Canaanites were a corrupt people and God exercised judgement--righteous judgement--upon them. It is comparable to what happened centuries earlier to the towns of Sodom and Gomorrah. It might be tempting to pause and catalog the detestable practices of these cursed folks--child sacrifice, for example, or bestiality, or the worship of entities that at best were impotent idols, or at worst may have been demonic forces--but that would be beside the point.
In fact, we are all of us Canaanites. We are no better or worse in many ways than those Dagon worshipping Philistines, or the Molech worshiping Ammonites. The question could be framed not so much "why did He do that to the Canaanites?" But rather "Why not all of us? Why is any of us still here? Why hasn't God just blotted us all out and started over?" (Genesis of course asserts that God did attempt a "reboot" with the Great Flood, but that's another story). What God did to the Canaanites is deserved by everyone. Christians dealing with the concepts of sin and death might assert that God would be perfectly just in sending a Vogon battle cruiser to wipe out our planet (a la Douglas Adams' Hitchhiker's Guide to the Galaxy). We wouldn't like it, but it would be just.
All humans everywhere fall under a judgement of death. Sin is universal. A familiar verse to most who have grown up in Sunday schools is Paul's admonition that "all have sinned and fallen short of the glory of God." We are told not many words later that "the wages of sin is death".
In fact, Christians would even go so far as to say that sin is the very reason that we all die. An argument made about Jesus in the New Testament is that because he was sinless, "death could not contain him." The first sin of our forebears brought a curse upon a previously immortal race, and they became mortal. Death is universal, because sin is universal.
However, the Bible also asserts that mercy is God's prerogative: “I will have mercy on whom I have mercy, and I will have compassion on whom I have compassion.” Every breath we take that isn't snuffed out, every moment of continued existence of planet Earth, is an undeserved mercy, a special gift of grace, from the God of holiness and goodness. A mercy is not "injustice", but it is a kind of "non-justice"--these are not quite the same thing. Luckily, this is not the only mercy we have from God.
Now, this isn't the whole answer; Were we to stop here you could rightly be dissatisfied. You might point out that by this line of argumentation, every tyrannical despot who gasses his own people, or even every serial killer who strangles randomly chosen girls, is simply doing God's work.
2. Murder in other contexts is unrighteous.
The magnitude of difference between someone like Josef Stalin and the Lord God is as wide a chasm as the distance from here to the Andromeda nebula, but this fact will nevertheless be hard for those dorm room philosophers to see. The key difference: One is righteous, and one is not. One is exercising divine judgment upon sin, and one is using murder for baser ends--in Stalin's case, murder was partly a kind of paranoia-driven crowd control, and partly elimination of rivals, and the accumulation of power. Some humans murder for money, or out of jealousy, or to shut the baby up, or to fulfill sick lusts. The motivation and reason is a crucial distinction.
When humans murder, unless commanded by God, it is a usurping of God's prerogative. When we kill we are like butchers hacking apart meat; when God kills, He is a surgeon, trying to remove a cancer. When we kill, we are oafs trampling a garden, when God kills He is a master gardener trying to eliminate an invasive weed.
I'll cover one last point here before I move on. God does not plant evil in the hearts of men, but God can use that evil intention for higher purposes. You may remember Joseph forgiving his wicked brothers when the tables were turned: "You thought evil against me; but God meant it unto good".
Generations after the Canaanite conquest, God used the wicked kings of the nations around Israel as His divine righteous arm of judgment against His own people for their wickedness and failure to honor the covenant.
3. God had a special role for Israel--and no, they didn't deserve it, either.
Israel had been given a special assignment--to be God's chosen people, a holy nation. In the words of St. Simeon (said of a person, Jesus, centuries later), Israel had a national calling to be "a light to enlighten the Gentiles." Israel was to radiate God's glory and be a testament to God's goodness: "...you shall be to me a kingdom of priests and a holy nation.” (Exodus 19:6)
The Israelites weren't inherently better than the Canaanites, and the Bible does not shy away from highlighting this fact. They weren't better, but God chose to use them. God honored an ancient promise to Abraham. The Hebrew people were rescued from slavery, and then called to become something better than they were. They were to be "holy" or "set apart"--no impurity, no idolatry, no paganism.
God consecrated the Hebrews, and set before them a special covenant:
“And if you faithfully obey the voice of the Lord your God, being careful to do all his commandments that I command you today, the Lord your God will set you high above all the nations of the earth. And all these blessings shall come upon you and overtake you, if you obey the voice of the Lord your God. Blessed shall you be in the city, and blessed shall you be in the field. Blessed shall be the fruit of your womb and the fruit of your ground and the fruit of your cattle, the increase of your herds and the young of your flock. Blessed shall be your basket and your kneading bowl. Blessed shall you be when you come in, and blessed shall you be when you go out." "...But if you will not obey the voice of the Lord your God or be careful to do all his commandments and his statutes that I command you today, then all these curses shall come upon you and overtake you. Cursed shall you be in the city, and cursed shall you be in the field. Cursed shall be your basket and your kneading bowl. Cursed shall be the fruit of your womb and the fruit of your ground, the increase of your herds and the young of your flock. Cursed shall you be when you come in, and cursed shall you be when you go out." (Deuteronomy 28:1-6; 15-18. ESV Bible)
The key here is that this was a special situation limited to a particular time and place. God doesn't call all Christians everywhere to wage "jihad" against all infidels in all corners of the earth. He did call upon one particular generation of His chosen people to go cleanse and purify one area of real estate.
4. God was right, they were wrong.
The fact is, the Israelites failed to commit fully to the task, and for hundreds of years afterward they struggled with idolatry--they felt the strong temptation to worship the false gods (idols) of those around them. This is precisely what God predicted: “In the cities of the nations the LORD your God is giving you as an inheritance, do not leave alive anything that breathes. Completely destroy them...Otherwise, they will teach you to follow all the detestable things they do in worshiping their gods, and you will sin against the LORD your God” (Deuteronomy 20).
Over and over again the "chosen ones" of God erred and strayed and provoked God's divine punishment. They worshiped Ba'al. They sacrificed their babies to the goddess Ashtoreth, and to the god Molech. They disobeyed the Law of God, "most justly provoking his wrath and indignation" (from Book of Common Prayer), until they finally were all but snuffed out by the Assyrians and then the Babylonians.