The sin that Klal Yisroel committed at the time of Purim was that they enjoyed the party thrown by Achashveirosh. They should not have participated in the festivities, since the very essence of the party was to celebrate what Achashveirosh believed: that the Beis HaMikdosh would never be rebuilt.
Incredibly, at the very moment the Jews were sinning, while they were eating, drinking, and enjoying a party celebrating Churban Beis HaMikdosh, Hashem was setting the stage for their salvation! Achashveirosh commanded Vashti to appear before the revellers, and her refusal to comply led to her execution. This enabled Esther to enter the palace as her replacement, where she was able to orchestrate the events that led to Haman’s downfall.
At the very time and place that the aveirah was being committed, at that very party where the Jews of Shushan were sinning, Hashem was planting the seeds of redemption. How did Klal Yisroel merit such remarkable Divine intervention if they were in the midst of grave sin at that very moment? The Ben Yehoyada (Megillah 12b) explains that the merit for their salvation is found in the divrei Torah and zemiros with which the Yidden elevated their Shabbos meals.
The Gemara includes this seemingly extemporaneous fact in its discussion about Vashti’s demise to advise us that this was the basis for the yeshuah. Klal Yisroel merited salvation specifically because of the divrei Torah that are shared at the Shabbos table. Relating divrei Torah at the seudas Shabbos elevated their Shulchan to the level of the mizbe’ach, which was in turn mechaper for their aveiros. They would then be worthy to be saved from Haman’s evil decree.
The Kesav Sofer (Shu”t, Orach Chaim 137) takes a similar approach in explaining why the festival of Purim was established to specifically be celebrated with mishteh and simcha. It was the zechus of the divrei Torah and zemiros that Klal Yisroel brought to their Shabbos tables that allowed their salvation to begin at the very party where their sins were being committed. We commemorate this by celebrating with a festive meal, with a seudah replete with delicacies. Klal Yisroel were saved because of the divrei Torah repeated at the seudah, and we honour this by enjoying a seudah prefaced by divrei Torah as well.