That period was meant to punish them, but if there's no choice, G-d uses Gog and Magog to also elevate the Jewish people, unite them, and bring them closer to G-d regarding the precepts and the Torah. 