The main purpose of the exile is, rather than a punishment, in order to purify us so that we can receive the great G-dly revelations in the Redemption through Moshiach. It’s a descent for the purpose of ascent. During the exile, we make “vessels” to receive the revelations of G-dly light.
This is why when the Ba’al Shem Tov asked the soul of Moshiach when he is coming, Moshiach responded, “When your wellsprings will spread outwards”. The light of Chassidus is the vessel for receiving the light of Moshiach, which is revealed when the vessel is complete.
(from a letter of the Lubavitcher Rebbe King Moshiach Shlita)