The gemara writes that midah tovah outweighs punishment by a scale of 500 to 1. Chazal illustrate the point from the fact that in the merit of Miriam having waited just a few moments to see that her baby brother Moshe was safe, the entire nation of Bnei Yisrael waited two weeks while Miriam overcame her leprosy . Tosfos (Sota 11a) is bothered by the apparent contradiction to this rule from the story of the meraglim. For every one day that the meraglim spent scouting out Eretz Yisrael, Klal Yisrael had to spend an entire year in the desert. That's not much different than the 500 to 1 ratio of midah tovah.
Tosfos in the end does not answer the question (see Maharasha), but the Sefas Emes offers a response (I did not find this in the Sefas Emes but saw it quoted in the Beis Yisrael). In reality, al pi derech hateva, Klal Yisrael should have had to spend 40 years in the desert. It should have taken that long for them to develop as a nation and be ready to deal with the challenges of yishuv ha'aretz. Hashem, however, wanted to do Klal Yisrael a favor and cram those 40 years of preparation into only 40 days. If only the meraglim had brought back a positive report and Klal Yisrael would have responded appropriately, job over! Since they didn't, they had to face reality and do the job the long way. The 40 years therefore were not an onesh -- they were simply the way things should have been if not extra special chassadim.
Says the Sefas Emes, once Klal Yisrael figured out over 40 years the tikun that was necessary and realized the mistake they had made, the power to effect the same result in only 40 days as originally planned became part of the collective spiritual yerusha of Klal Yisrael. We now know what needs to be done and can do it the quick way. Every year during these 40 days, from the beginning of Tamuz until 9 Av, we have a chance to do it right this time around.