The mitzvah of tzitzis appears at the end of parashat Shelach. Is there a connection between the story of the spies and this mitzvah? Any explanation why/if tzitzis is related to the main narrative of Shelach?
After the debacle with the spies, the parsha ends with parshas tzitzis which contains "וְלֹֽא־תָת֜וּרוּ אַחֲרֵ֤י לְבַבְכֶם֙". That seems to be the moral of the story of the spies in brief.
Just to develop this answer a bit, in the first pasuk of the next parsha (Korach), Rashi "ודתן ואבירם" brings how Korach used tzitzis with techeles to try to buttress support to legitimize why he was causing a revolution against Moshe. So it appears that parshas tzitzis is placed at the end of the parsha to give a message to the spies that precede it and to Korach that follows that one should not go against the Torah.
To add on to and explain Geltman's answer, the Gemara in Berachos 12b says:
"אחרי לבבכם" -זו מינות
"Stray after your hearts" - this is referring to heresy
Hashem told them to go into the land, and had promised in one form or another to protect the Jews several times. Being afraid of going into the land was an act of disbelief in Hashem and his promises. Thus, tzitzis serves as a protection against the mistake that the spies made.
So it appears in my eyes.
Tzitzit in general are a protection against immorality, which in turn is the aspect of the advice of the wicked.
Likutei Etzot - Emet w'Emunah #5, which is a digest of Likutei Moharan #7:3-4:
ה. אִי אֶפְשָׁר לָבוֹא לָאֱמֶת אֶלָּא עַל־יְדֵי הִתְקָרְבוּת לְצַדִּיקִים אֲמִתִּיִּים וְיֵלֵךְ בְּדֶרֶךְ עֲצָתָם וְלֹא יִטֶּה לְיָמִין וְלִשְׂמֹאל מִדִּבְרֵיהֶם וְעַל־יְדֵי זֶה נֶחְקָק בּוֹ אֱמֶת וְזוֹכֶה לֶאֱמוּנָה וְכוּ' וְכַנִּזְכָּר לְעֵיל, וְכֵן צָרִיךְ לְהַרְחִיק אֶת עַצְמוֹ מֵעֲצַת רְשָׁעִים וּמִתְנַגְּדִים וְחוֹלְקִים עַל הָאֱמֶת. וְכָל זֶה זוֹכִין עַל־יְדֵי מִצְוַת צִיצִית שֶׁהוּא בְּחִינַת שְׁמִירָה מִנִּאוּף שֶׁהוּא בְּחִינַת עֲצוֹת רְשָׁעִים, וְזוֹכִין לְתִקּוּן הַבְּרִית שֶׁהִיא בְּחִינַת עֵצוֹת שֶׁל צַדִּיקִים (שָׁם ג).
The only way to find truth is to draw closer to the Tzaddikim and follow their guidance. Do not turn aside from their words either to the left or the right. Then the truth will be engraved within you and you will achieve genuine faith. By the same token, keep well away from bad influences. Pay no attention to the suggestions of those who are the enemies of the truth, who raise every kind of question about the truth. You can succeed in this through observing the mitzvah of tzitzit, the fringes. (See Tzitzit #1). Tzitzit are a hedge against immorality which is directly contrary to the Holy Covenant between God and the Jewish people and is one of the strongest forces which can undermine truth. The guidance and advice of worthless people actually breeds immorality. Through observing the mitzvah of tzitzit you will be able to purify yourself and observe the Covenant, which is the foundation of faith. All the teachings of the Tzaddikim are bound up with this (Ibid. 3).