http://revach.net/article.php?id=76

Section: Parshas HaShavua   Category: Quick Vort
Parshas Shemini: Meshech Chochma - The Death Of Tzadikim

The Meshech Chochma explains that the whole purpose of Nadav and Avihu's deaths was to cause a Kiddush Hashem.  When the tzadikim are punished for small aveiros, people realize that they themselves need to seriously rectify their own behavior.

Hashem's resting of his Shechina on the Mishkan was a sign that He forgave Bnei Yisrael for Chait Ha'Egel.  Therefore, Bnei Yisrael may have gotten the mistaken impression that even when they do a severe aveira like the egel, Hashem will quickly forgive them and that Hashem is a "Vatran".  Therefore, by instantly killing two great tzadikim like Nadav and Avihu for a small aveira, Hashem restored the fear of His judgement among the people.  Therefore, their perfectly timed deaths on this very day caused a great Kiddush Hashem.