Another interpretation: so that they would not see the bones of their brothers thrown about in Philistia and turn back. Another interpretation: so that they would not turn back on their tracks. And the matter is an argument from minor to major: if when He led them around by a crooked road they still said (Numbers 14:4), "Let us appoint a leader and return to Egypt," how much more would they have said this had He brought them by the direct way. Another interpretation: "when they see war" (Exodus 13:17) refers to the war of Amalek, as it is said (Numbers 14:45), "Then the Amalekite and the Canaanite came down."
Why the LORD Led Israel the Roundabout Way From Egypt
Yalkut Shimoni on Torah 227:4
דָּבָר אַחֵר, כְּדֵי שֶׁלֹּא יִרְאוּ אֶת עַצְמוֹת אֲחֵיהֶם מֻשְׁלָכִים בִּפְלֶשֶׁת וְיַחְזְרוּ לָהֶם. דָּבָר אַחֵר, כְּדֵי שֶׁלֹּא יַחְזְרוּ לַאֲחוֹרֵיהֶם, וַהֲרֵי דְּבָרִים קַל וָחֹמֶר אִם כְּשֶהִקִּיפָם דֶּרֶךְ (רְחוֹקָה) [עֲקוּמָה] אָמְרוּ (במדבר יד, ד) "נִתְּנָה רֹאשׁ וְנָשׁוּבָה מִצְרָיְמָה" עַל אַחַת כַּמָּה וְכַמָּה אִלּוּ הֵבִיאָן בִּפְשׁוּטָה. דָּבָר אַחֵר, בִּרְאֹתָם מִלְחָמָה, זוּ מִלְחֶמֶת עֲמָלֵק שֶׁנֶּאֱמַר (שם מה) "וַיֵּרֶד הָעֲמָלֵקִי וְהַכְּנַעֲנִי".