Almost immediately after their victory over a great walled city (Jericho) the scouts of the army report back that Ai is a small city that will be easy to capture, so they shouldn’t bother sending the entire army. These scouts tell Joshua that a few thousand men will be more than enough to take the city, but they loose the battle and get chased from the field by the men of Ai.
Joshua is greatly disturbed and rightly assumed this was some kind of message from God. After some narrowing down, they come to the family of the man that sinned and caused this defeat. He admitted to taking booty against the direct instructions of God, and that’s why they lost this battle.
For his transgressions that brought defeat to the nation, he is taken out and stoned to death. This is an early and stark message to Israel that if they obey and follow the commands of God they’ll have great victories, but disobedience brings epic defeats.
So after rooting out the sin in their camp, they go back up against the city with an ambush set up behind them. When the men of Ai seen them they came out and took the bait, and their city was destroyed.
Jesus warns his disciples about the need for watchfulness. He makes the comparison to a servant staying awake so that he’s not surprised by his master arriving home late. This is usually interpreted as an end of days warning, and it certainly can be seen that way, but it’s also a warning to be prepared to meet Jesus at the hour of our death, and that it can be at a very unexpected time, so we must remain vigilant.
Jesus even takes the crowds to task because they don’t understand what is happening right in front of them. He says they know how to interpret the weather and things of nature, but they can’t interpret the signs performed in front of them.