Israel defeated Jericho with no losses. They went to the next city, Ai, and expected the same victory, but not only did it not happen, Israel lost soldiers, and the men of Ai chased the Israelites. Joshua wondered why the Lord had forsaken Israel, but the Lord revealed the problem was not Him, it was Isarel,
So the Lord said to Joshua: “Get up! Why do you lie thus on your face? Israel has sinned, and they have also transgressed My covenant which I commanded them. For they have even taken some of the accursed things, and have both stolen and deceived; and they have also put it among their own stuff. Therefore the children of Israel could not stand before their enemies, but turned their backs before their enemies, because they have become doomed to destruction. Neither will I be with you anymore, unless you destroy the accursed from among you” (Joshua 7.10–12).
The Lord had said that everything in Jericho belonged to Him, and then at the other cities Israel could take what they wanted. However, at Jericho one of the Israelites had taken something that belonged to the Lord, and for that the whole team suffered, just as a sports team suffers for the foul of one of its players.
Therefore, keep yourself pure that you may not hurt the church.