Why was God fair in commanding Joshua to destroy all the Canaanites?
God was fair because the Canaanites' iniquity had become full; they had gone so deeply into sin and wickedness that judgment was fully deserved. He had patiently allowed Israel to suffer in Egypt so the Canaanites could prove the worthiness of that judgment. Thus God was perfectly fair in commanding Joshua to destroy them all.
Les explains that back in Genesis 15, God told Israel they would stay in bondage until the Canaanites' iniquity was full. Because the Canaanites had gone so deep into sin and wickedness, God was perfectly fair in telling Joshua to kill them all—not sparing even an infant or an old person. If they spared one, that person would be like a rotten apple in a barrel, causing the rest to go bad. God patiently let His own people suffer in Egypt so the Amorites and Canaanites could prove the worthiness of the judgment coming upon them. The pitiful part is that Israel did not carry it out, and just as God said, they went down to the Canaanites' level.