In Parshat Shoftim, the Torah (17:16) says that a king “shall not acquire many horses for himself.” This statement, however, only applies to horses that are acquired for the sole purpose of glorifying and honoring the king. Horses that are necessary for the king’s army or for his traveling caravan, however, may be acquired. This leniency is found a number of sources, including the Gemara (Sanhedrin 21b), which deduces from the words “for himself” that only extraneous horses are prohibited. The Rambam in Hilchot Melachim (3:3) also states that a king may acquire horses for his army. Similarly, the Sefer Hachinuch writes, “Zulati HaTzrichim LeMerkavto, VeInyan HaMitzvah Shelo Yihyeh Lo Susim SheYarutzu Lefanav LeKavod BeAlma,” “[He may not acquire horses] excluding those that are needed for his chariot, and the issue of this mitzvah is that he should not own horses that run in front of him for general honor.” Obviously, the army is not considered “general honor” and is therefore not included in this prohibition.
The importance of allowing horses to be acquired for the army is evident from the commentary of Rav Shimson Rafael Hirsh, who points out that the horse was considered a war animal (and a necessary one), which is why we must allow the king to have them in his army. He than proves his point with examples from Tanach of horses being used in battle. Note, however, that in Chapter 11 of Sefer Yehoshua, Yehoshua hamstrings the horses and burns the chariots the kings in Israel whom he conquered (also see Shmuel II 8:4).
Despite the need for horses in battle, one might think it is good to limit these horses as well to prevent haughtiness from the king. This is especially true given that the Torah tells us in 20:13, “Untanam Hashem Elokecha BeYadecha,” “Hashem your God will deliver [your enemies] into your hands.” If Hashem will cause us to be victorious anyway, what is the purpose of risking a haughty king for a stronger army? This is why the Gemara and commentaries had to tell us that battle-horses were allowed: to teach us that even though Hashem controls everything in the end, we may, and in fact must, do our best to prepare for every situation.