What lesson was God trying to teach Israel by commanding them to remove the rot?
God was teaching Israel that corruption is contagious. The Canaanites' deepening wickedness would infect Israel's sons and grandsons if the land was not totally cleansed. Removing the rot was necessary because otherwise it would infect and destroy Israel, and God would then have to deal with them.
Les teaches that God had waited nearly four hundred and ninety years, from Abraham's call until Joshua led Israel in, for the Canaanites to turn from their iniquity, but they did not. Instead they went deeper into wickedness, immorality, and abominations. Finally God told Joshua to instruct Israel not to spare a one of them, because unless the land was totally cleansed, Israel's sons and grandsons would soon be just like the Canaanites. Les uses the illustration of good apples or potatoes in a container: if you put one half-rotten one in the middle, it is not long until the whole group is just as rotten. That is exactly the lesson God was teaching Israel: you have to remove the rot, because unless you do, it will infect you, destroy you, and then God will have to deal with you.