There is a custom quoted in SA (OC 580) to fast on 17 Elul as this is the anniversary of the day the meraglim died. The MB (sk 8) quotes the Beis Yosef as asking why we should commemorate their death. We have fasts for the death of tzadikim, e.g. Aharon's death, Miriam's death. However, when it comes to reshaim, וּבַאֲבֹ֖ד רְשָׁעִ֣ים רִנָּֽה. We should celebrate their death, not mark the day with a taanis.
The Beis Yosef answers ואפשר דמסתמא שבו ולא זכו שיקובל תשובתם ולכן מתענים. It's hard to understand what he means. If their teshuvah was not accepted, then that means they remain reshaim and הדרא קושׁיא לדוכתא. But even if they had succeeded in doing teshuvah, does that now make them tzadikim deserving of their own fast day?
R' Moshe Tzuriel answers that the fast of 17 Elul is a fast not for the meraglim, but for ourselves, for Klal Yisrael, because it was our acceptance of the meraglim's report and our rejection of Eretz Yisrael that led to the bechiya l'doros of future churban and galus. You might argue that we already have a fast of 9 Av for that, but there is a need for both days. 9 Av is a day of mourning over the final outcome of churban, which came as a result of sinas chinam. 17 Elul is a day to reflect on וימאסו בּארץ חמדה, the sin that got the ball rolling.
Maybe we can salvage the reputation of the meraglim and explain why we fast in their honor with the help of a Chasam Sofer. There is a puzzling Yalkut Shimoni that says:
מֵעִיד אֲנִי עָלַי שָׁמַיִם וָאָרֶץ שֶׁלֹּא הָיְתָה בְּדַעְתּוֹ שֶׁל הַקָּדוֹשׁ בָּרוּךְ הוּא לְהָמִית עֲשָׂרָה נְשִׂיאֵי יִשְׂרָאֵל, אֶלָּא שֶׁרָצוּ אַחַר מֹשֶׁה וְאַהֲרֹן עַד שֶׁנִּכְנְסוּ תַּחַת כַּנְפֵי הַשְּׁכִינָה.
Somehow the death of the meraglim is attributed to their following Moshe and Aharon, which is very hard to understand. How would following Moshe nd Aharon cause someone to die? On the alhatorah.org website they quoted this Yalkut and add a few words in brackets: שֶׁרָצוּ אַחַר מֹשֶׁה וְאַהֲרֹן [לִרְגֹּם אוֹתָם בַּאֲבָנִים] I'm not sure where the bracketed words come from, but they obviously come to address this difficulty by saying it wasn't following Moshe and Aharon that led to their death, but rather trying to kill Moshe and Aharon. Quite a difference! The Chasam Sofer quotes the Yalkut and the Tana d'Bei Eliyahu without those words, and has a few different suggestions to explain what Chazal mean.
Before getting to his hesber, let me preface it with acomment from a talmid of CS in a footnote citing a vort from his rebbe the CS. He writes that R' Akiva's view in Sanhedrin 108a דּוֹר הַמִּדְבָּר אֵין לָהֶם חֵלֶק לָעוֹלָם הַבָּא וְאֵין עוֹמְדִין בַּדִּין שֶׁנֶּאֱמַר {במדבר י״ד:ל״ה} בַּמִּדְבָּר הַזֶּה יִתַּמּוּ וְשָׁם יָמוּתוּ דִּבְרֵי רַבִּי עֲקִיבָא should not be taking at face value. In potential, the dor ha'midbar might have theoretically been at risk of losing olam ha'ba. In reality, however, the opposite is the case. Read the entire pasuk:
אֲנִ֣י ה׳ דִּבַּ֒רְתִּי֒ אִם־לֹ֣א׀ זֹ֣את אֶֽעֱשֶׂ֗ה לְכׇל־הָעֵדָ֤ה הָֽרָעָה֙ הַזֹּ֔את הַנּוֹעָדִ֖ים עָלָ֑י בַּמִּדְבָּ֥ר הַזֶּ֛ה יִתַּ֖מּוּ וְשָׁ֥ם יָמֻֽתוּ׃
What Hashem is saying is אִם־לֹ֣א׀ זֹ֣את אֶֽעֱשֶׂ֗ה -- if not for the fact that they are going to be punished, then בַּמִּדְבָּ֥ר הַזֶּ֛ה יִתַּ֖מּוּ וְשָׁ֥ם יָמֻֽתוּ. They are, however, going to be punished. That punishment is therefor in effect their salvation.
Here is the hesber of the CS to the Yalkut (there are different editions of CS, so it's not so easy to find):
In this piece the CS is saying that the dor ha'midbar were punished, but there was a silver lining. No one died before age 60, giving them each the opportunity to grow to shleimus. יִתַּ֖מּוּ = achieve temimus, and only then יָמֻֽתוּ. (See the chiddush if the Akeidah in this post.)Does that mean that the meraglim who were killed on the spot were denied that opportunity and were doomed forever? Quite the contrary, says the CS. The meraglim were the only members of dor ha'midbar who had the zechus of walking 4 amos in Eretz Yisrael. The meraglim were the ones who when Moshe and Aharon asked for volunteers to go ahead and spy out the land, they raised their hands and took the mission knowing full well the dangers that would be involved. These people didn't need 40 more years in the desert to achieve shleimus before they died. They had achieved shleimus already! True, upon their return they sinned in bringing a false report, but that sin does not outweigh the merit of their accomplishment.
What Chazal in the Yalkut are asking is why did the meraglim, unlike anyone else, **merit** immediate death in a state of shleimus? The answer is אֶלָּא שֶׁרָצוּ אַחַר מֹשֶׁה וְאַהֲרֹן. Because they were the pioneers who trusted Moshe and Aharon, who embarked on an uncertain mission, and were thereby the first ones since the Avos to have the zechus of walking in Eretz Yisrael. Their sin may have been great, but their merit is even greater.
We fast on 17 Elul to celebrate the greatness of Eretz Yisrael, to celebrate the fact that the heroism and faith of being willing to enter the land in the face of risk and uncertainty can overcome and erase other faults and failures.