One school of Midrash (Lev. R. 12) thinks they were impudent towards God and had to be punished.
Another, reported in the Talmud (Zev. 115b) says they died in order to sanctify the honour of God. They loved Him so greatly that they yearned to rise above their physical bodies and attach their souls to the Almighty. Their death was a reward for their piety; as the Psalmist says, “Precious in the sight of the Lord is the death of those that love him” (Psalm 116:15).
According to this approach, we read their story on Yom Kippur in order to inspire us to dedicate ourselves to God with every fibre of our being.