Verse 21: And when Joshua and all Israel saw that the ambush had taken the city, and that the smoke of the city ascended, then they turned again, and slew the men of Ai.
[And Joshua seeing] Joshua is said to have done this, not because he himself fought with his own hands (Bonfrerius) (for it is certain that he did not take part in the fight, but he stood fixed in some place apart, extending his hand toward the city [Masius]), but because by his leadership and command this was done, with Joshua (as has been said) concurring morally toward victory (Bonfrerius).
[All Israel] Either thus are called those that had feigned flight with Joshua; or, if you prefer this, those are signified under the appellation Joshua: now, all Israel was joining itself to their fellows feigning flight (Masius).
All Israel, that is, all the Israelites there present, or all those who seemed to flee away before.
Verse 22: And the other issued out of the city against them; so they were in the midst of Israel, some on this side, and some on that side: and they smote them, so that they (Deut. 7:2) let none of them remain or escape.
The other; they who lay in ambush. So their late success was a real mischief to them, as being the occasion of their total ruin.
[In such a way that no one was spared] Hebrew: until there did not remain to them a survivor or escapee (Montanus). שָׂרִיד signifies one that is taken alive by enemy; but פָּלִיט, one that escapes by flight. And they are certainly forbidden to spare those captured. And here we plainly see that the pious are punished by God unto salvation, but with respect to the impious their felicity is to destruction. Wherefore with equanimity let us entrust the management of our affairs to God. Let us not measure with our reason what things appear to turn out adverse to the pious, favorable to the impious (Masius).
 Hebrew: וִיהוֹשֻׁ֙עַ וְכָֽל־יִשְׂרָאֵ֜ל רָא֗וּ כִּֽי־לָכַ֤ד הָֽאֹרֵב֙ אֶת־הָעִ֔יר וְכִ֥י עָלָ֖ה עֲשַׁ֣ן הָעִ֑יר וַיָּשֻׁ֕בוּ וַיַּכּ֖וּ אֶת־אַנְשֵׁ֥י הָעָֽי׃
 Hebrew: וְאֵ֙לֶּה יָצְא֤וּ מִן־הָעִיר֙ לִקְרָאתָ֔ם וַיִּֽהְי֤וּ לְיִשְׂרָאֵל֙ בַּתָּ֔וֶךְ אֵ֥לֶּה מִזֶּ֖ה וְאֵ֣לֶּה מִזֶּ֑ה וַיַּכּ֣וּ אוֹתָ֔ם עַד־בִּלְתִּ֥י הִשְׁאִֽיר־ל֖וֹ שָׂרִ֥יד וּפָלִֽיט׃
 Hebrew: עַד־בִּלְתִּ֥י הִשְׁאִֽיר־ל֖וֹ שָׂרִ֥יד וּפָלִֽיט׃.
 שָׂרִיד is derived from the verbal root שָׂרַד, to escape.
 פָּלִיט is derived from the verbal root פָּלַט, to escape.