Yahweh said to Joshua, Don't be afraid, neither be dismayed: take all the people of war with you, and arise, go up to Ai; behold, I have given into your hand the king of Ai, and his people, and his city, and his land;
We do not pretend to know the proper solution of this obvious difficulty, but, in all probability, the difficulty itself lies in the complexity and weakness of the Hebrew style of narrative, with the problem of the Hebrew tenses making it virtually impossible, at times, to determine the chronology of several parallel actions occurring simultaneously.  Aside from this one tiny problem, the grand action of this chapter is as clear as broad, open daylight.