Ruh-roh! This is the story of Achan, a member of Judah's tribe, who sins and gets the entire nation of Israel punished as a result.
The backstory: Joshua sends some spies to Ai, a village in a valley near Jericho. They come back and report that only a couple of thousand men will be needed to defeat the town, for they are but few (v. 3).
Unfortunately, the men of Ai are fiercer than expected, and manage to kill 36 Israelites before they retreat. Oh, no! A one percent mortality rate! Apparently Joshua thought he could conquer this entire territory without losing anyone. That's why he had a 600 000 person army, of course.
Anyway, he laments and tears his clothes and asks god why he sent them here to be humiliated. God informs him that one of his soldiers stole something, then lied about it and hid it among his possessions. He tells Joshua to find out who, and kill the traitor by burning, you know, rather than acting like the omniscient, omnipotent god he supposedly is and doing it himself.
So the next day, Joshua enquires through the ranks and finally comes to Achan, who readily admits to taking a goodly Babylonish garment, and two hundred shekels of silver, and a wedge of gold of fifty shekels weight (v. 21) and burying it under his tent. Rather than praise him for his honesty and forgive him, Joshua takes his entire family and his animals to the valley of Achor, where they are first stoned, then burned to death and buried under a heap of rocks.
So much for those verses that say not to punish a man for his father's sins. Also, why does god keep insisting on stoning animals to death? Why do biblical animals have moral agency?
According to The Skeptical Review, the two cities of Jericho and Ai were abandoned around the same time, 2400-2300 BCE, or 1000 years before all of this supposedly took place. This story is an etiology (story that explains the existence of a phenomenon). Of course Jerry Falwell, who was all over the fact that there was an Egyptian Pharaoh who wasn't his father's firstborn son in 1800 BCE must be proof of the plague of firstborn sons, doesn't mention this little piece of archeological evidence.
God commands the Israelites to go again and conquer Ai. Joshua takes 30 000 men this time. He orders them to fake a retreat, following which they'll burn the city. The plan works and they kill everyone inside. The king is hung in a tree and buried near the entrance of the city, with a pile of stones marking the site.
Joshua then builds an altar at Mount Ebal, where he sacrifices some animals. Then he writes all the laws on some stone tablets