The priests blew the trumpets. As soon as the fighting men heard the sound, they gave a loud shout. Then the wall fell down. Every man charged straight in. So they took the city. They set it apart to the Lord in a special way to be destroyed. They destroyed every living thing in it with their swords. They killed men and women. They wiped out young people and old people. They destroyed cattle, sheep and donkeys. (New International Reader's Version)How could He? How could God allow the people of an entire city to be destroyed? This type of wholesale destruction and death is recorded several times in the Old Testament. I don't think God wants us to gloss over these things just because they bother us. I also think it is important to place these events in the context of the rest of the Bible. To be honest I don't have an answer that completely satisfies. To me the closest I get to understanding this is in the context of God's overall plan. Perhaps it can only be understood in the light of God's Son.
J.D. Hatfield puts it this way."... this slice of redemptive history must be looked at within the overall context of God’s plan. And that plan included pouring out His wrath upon His own Son to pay for our sins. So before you can ask about the Canaanites, and the Jews before them, how about the fact that God poured out His wrath upon the sinless Son of God?
Love must be seen in its full context. If you had a child learning to ride a bike, and you were that day going to remove the training wheels, you would realize that they might fall, and skin their knees. They would be hurt, and would be very angry with you. However, you know that in the long run it was good for them. You knew the big picture. They might be mad for a while, perhaps a long while, but when they learned to ride that bike they would be glad you helped them learn how.
God gives us the big picture of redemption, and all we have to do is look at the cross to see that God is vitally concerned about punishing sin. Yet he allowed His own Son to pay for that sin because He is also vitally concerned about demonstrating His love. So instead of looking at only those early moments in redemptive history, be sure to look to the climax of it, Jesus Christ, the sinless Son of God, dying on a cross to reconcile you to a loving God."