Note the difference of the ways of God. In Ai there is positive sin—lust is at work in the camp—God will not go out with the host, nor justify and so strengthen sin by letting it go on unnoticed. In Gibeon there was false self-confidence after blessing—they did not consult God, hence bound to their enemies. They are obliged to defend and hinder the destruction of the very thing they ought to have destroyed or possessed. They are not beaten, but obliged, though conquering others, as regards Gibeon to be strong to their own prejudice, and preserve what, in weaker times, would be a thorn in their sides.
Another instruction here is that, led of the Lord, Joshua is not, by the attack of his enemies, turned aside to follow them, or hindered from pursuing the course which the Lord Himself sets before him in his conquests. He takes the cities which are on the road the Lord leads him.
29. Note the taking down the king of Ai—God's possession of the land as pure; and the altar on mount Ebal—the people putting themselves in relation with God as brought there by Him, on the ground of thanksgiving—enjoyment, but of condition under, more.