A most perplexing Midrash features in Rashi 14:34. Commenting closely on the unusual wording of the pasuk, Rashi writes that HaShem promised us that when we go into the Land of Israel we will contract tzara’as on our houses. Why?
So that when we have to knock down our houses in the consequent purification process we will find ancient treasure which was buried underneath our houses. Splendid. But how can we understand this – surely the tzara’as only came because we sinned; so why is HaShem rewarding us with treasures for having sinned? The basic idea is found in Da’as Zekeinim (Vayikra 12:8) that these forms of tzara’as actually serve to atone for the sin.
Thus, after one has successfully been through the tzara’as purification process and has become a new spiritually-gleaning person, then one is worthy of reward for your spiritual turnabout. And since one of the sins that causes tzara’as is stinginess (a midah which you have now become re-sensitized to after the purification process), what better way to be rewarded than via riches galore!