In battle, the army of Israel is not to run away in fear from before their enemies. Rather, the soldiers are obligated to summon their courage and stand their ground. This mitzvah is repeated in several places. Aside from here, it is stated in Deuteronomy 3:2 and 7:21.
Battle is a time to think about the big picture. Every soldier is out there fighting on behalf of the nation. A single cowardly soldier can have a contagious effect, infecting an entire battalion with fear. The soldier who cannot overcome his fear is responsible for any casualties caused by his cowardice. The Talmud tells us (Sotah 44a) that officers were empowered to cut the legs of anyone attempting to go AWOL during battle.
The basis of this mitzvah is that running away in battle demonstrates a basic lack of trust in God. This doesn't mean that we should be foolhardy or go into battle unprepared but He did tell us to have faith in Him. An inability to move ahead shows that we have not been successful in placing our trust in Him.
This mitzvah applies at a time when the Jews reside on their land. It is discussed in the Talmud in tractate Sotah on pages 44a-b. It is codified in the Mishneh Torah in the seventh chapter of Hilchos Melachim. This mitzvah is #58 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos.