How about another possible scenario, just looking at the situation at it's face value?
They had 40 years in the wilderness, seeing God perform miracle after miracle, daily: even providing them food and water in that barren wasteland. They saw the power of God exhibited in many ways.
Was it such a big stretch for God to expect them to do as he said?
As their Father, He: led them by clould and a pillar of fire, fed them, kept them healthy, protected them, prospered them, gave them peace, gave them a way to have a relationship with him, and gave them victory over all opposition, as well as "spanking" them when they did a "booboo".
The wilderness was a place for their testing and Moses made this perfectly clear. If God gave them a straight shot from the first mountain after Egypt to right near the Jordan river in front of the land flowing with milk and honey, it would have only taken 11 days to get there.
Deut. 1:2,3
If there is one thing that will get you to see just how short of a fuse God has about failure to trust him, it's murmuring and complaining... especially when he shows you firsthand through signs and miracles for 40 years wandering, that He will to take care of you, (and your footwear still looks like it just came out of the box).
God wanted that 'victim of circumstance' complaining, and that 'slave mentality' murmuring gone. That is what the 40 years, looking at the bigger picture, seems to be all about. Dissatisfaction with such provision from God is no way to get on His good side. That is why the carcasses of the first generation found final rest while still treading desert sands.
They had 40 years to see the results of disobedience, and still one family disobeys? Yes, family.
Do you really think one member of a household can hide even the smallest bit of gold or whatever from everybody else living in your tent, much less the camp?
It doesn't seem very smart to try such. A person may get lucky enough to sneak it by the camp, but your wife... you kids, and that nosey judgemental mother in law?
Is God unrighteous in His judgements?
Father Abraham's plea bargaining over Sodom gives us a clear perspective on just how much God will tolerate sin in the city.
Gen. 18:25,32 / II Peter 2:9,10
Moreover, though God already knew the whole deal about Sodom and Gohmorrah, still He bothered to, in His elohim(ic) presence, walk in to see it with His own eyes before everlasting fire ever rained down from the sky purging that ground from the wickedness there. Still, God made a way for the righteous to escape.
We are not given the total picture of just exactly what happened before Ai, but we can be very sure God does not make mistakes. God did have the total picture right down to the most minute detail.
What did God say to Samuel when he was sent to annoint God's choice for another king over Israel? Samuel was looking for a brawny tall fellow who seemed to have his wits about him. After Saul failed God because his heart was lifted up>(proud), Samuel goes to the house of Jesse in Bethlehem, and those whom he considers annointable, God tells him "nope, not that one"... "Nope, not that one either", "no, not him..." (It's I Samuel 16> a good read)
In relation to the Ai failure after Jericho, regarding God's judgement, along with the Genesis passages, consider I Sam. 16:7 and give special note to the last three words of II Pet. 2:10
Everybody knew the rules, and they had 40 years of practice learning to obey or face the consequences. They were well aware that the only all seeing, all hearing, all knowing, merciful loving and kind God, judging rightly, dwelt right in their midst.
God is far from unfair in His judgement, though we do not have the total picture. Face it, if you or i were God, this planet would not even exist anymore, much less anything on it's surface. Sin has ruined our intentions and perceptions. His remains untainted. Without him, we do not even have the ability to forgive (how'd the whole wedding thing go BTW?), yet he gives good things to the just and unjust daily. He is grieved by the death of the wicked even though they tick Him off.
Are we His children? Do we show it by loving our enemies?
Instead of wondering whether God did the wrong thing or not, i have always left such passages until i understood Him further. It has helped me a whole bunch.
God's delight is in doing three things, and these 3 things, in this order listed are the priority by which he operates, though all of them are manifested every time He does something.
Jer. 9:23,24