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?
The story of the spies and the mitzvah of tzizit are connected through the story of the wood gatherer.
"A midrash suggests that when God decreed, in the wake of the sin of the spies, that the desert generation would not enter the Land of Israel, some thought that mitzva observance was no longer obligatory. The wood gatherer wished to teach them that everyone must continue to keep the mitzvot. Motivated by exceptional religious fervor, he decided to publicly desecrate Shabbat, so that the nation would be forced to put him to death. This would show everyone how serious the transgression was (quoted in Tosafot, BB 119b)." Peninei Halacha
"When Moshe saw the deed of the wood-gatherer he said to Hashem: On a weekday the Bnei Yisroel wear tefillin and they remember the commandments, how will they remember on Shabbos? Hashem answered: I will give them the commandment of tzitzis with which they will remember." Or HaChaim
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).
According to the S'fat Emet:
הי' להם במדבר ג' מתנות הטובות מן ובאר וענני כבוד. ולכן קשה להם לצאת מן המדבר. וניחם הקב"ה אותנו כי נשאר הארה מאלה הג' מתנות. וחלה ונסכים הוא זכר ממן ובאר. וציצית בהי' החסד ענני הכבוד.
In the wilderness, the Israelites had three great gifts: manna, the well, and the clouds of glory. Thus it was difficult for them to contemplate leaving the wilderness and entering the promised land. The Holy One, ever to be blessed, consoled them: some of the light of these three gifts remained to them. The commandment to separate bread and wine as an offering, these recall the manna and the well. And the commandment to surround oneself with fringes, this relates to the grace of the clouds of glory.
This specifically relates to his idea that the Twelve Spies wanted to retain the stauts of total spirituality, living in the wilderness with all needs provided for.,