But the people of Israel broke faith in regard to the devoted things, for Achan the son of Carmi, son of Zabdi, son of Zerah, of the tribe of Judah, took some of the devoted things. And the anger of YHWH burned against the people of Israel.
Joshua 7:1

Only Achan and his family sinned in stealing devoted items from Jericho, but the whole nation was counted guilty by God. Strict individualism is foreign to God's Law. We are judged as individuals, but also as families, cities, and nations. Ai was a small city that should have been easy for Israel to defeat, but once again victory is shown to depend, not on strategy or strength, but on faithfulness to God. It was a relatively minor defeat, yet the people's hearts melted from fear because of it. They weren't afraid because they had lost a few men. They were afraid because that loss indicated that God was no longer fighting for them.