Question: Rashi ([Bemidbar 13:25](http://www.chabad.org/library/bible_cdo/aid/9941#v=25&showrashi=true)) implies that the Jews were in the Sinai Desert for 40 years in response to the spies being in the Land of Israel for 40 days.

While the spies had 40 days worth of planning to sin, and thus were punished, why were the Jews punished for merely accepting the spies’ report? What do they have to do with the 40 days?

Answer: 
The Kli Yakar on יום לשנה says that the punishment actually took place one day a year on Tish'a B'Av. Thus they were punished for "forty days" but the forty days were spread over 40 years. The punishment was that all those who should have been in the army and insisted on not listening to the spies (ages 20 to 60) were allowed to live out their "service life" and were punished by dying at age 60. Rabbi Munk says that since those who had turned 60 the previous year died on each Tish'a B'Av, it took forty years for the punishment to complete. This allowed the children (under 20) to grow up and replace them so that there was a fully trained and complete community ready to go into Canaan.

This was actually the manifestation of Hashem's Rachamim (mercy). Note that the medrash says that hashem shortened the time of the meraglim in the land so that the trip would take forty days. Rav Shimshon Rafael Hirsch says 

> 
> by fitting this time of the duration of the punishment in proportion to the sin, the sin is kept in the minds of the penitents during the whole course of the duration of the punishment. THis method, by which, simply by using some external similarity of numbers, something is brought to, and kept in, the mind, is frequently used by our sages in their institutions.
> 
> 
> 

Bnei Yisrael had free will and could have resisted the temptation. However, Hashem knew of the possibility of the sin and the necessity of the punishment. As a result, he shortened the trip so that the punishment could be carried out in such a way as to ensure that the lesson had been learned.
According to tosafos yom tov in sota, chapter one mishna nine, d.h. vichein li'inyan hatova, the forty years was an act of kindness, not retribution. In reality the nation deserved instant death but in order that noone die under the age of sixty, Hashem stretched it out for forty years.