The gemara says (Megila 7b) that on Purim we need to get drunk until we don’t know the difference between Arur Haman and Boruch Mordechai. What does this mean?
He explains as follows. The Meforshim ask why was Paroh punished for enslaving the Jews if that was Hashem’s decree? They answer that Paroh in his cruelty went far beyond what Hashem decreed, and for that he was punished. If so asks the Chasam Sofer, Haman only tried to carry out Hashem’s decree of wiping out Bnei Yisroel r”l, why was he punished? The Chasam Sofer answers that had he done it to fulfill the mitzva of Hashem he would not have been punished. However he did it for his own pleasure and for that he was killed.
If so, says the Chasam Sofer, the only difference between Haman and Mordechai was the intent. Each one carried out their mission but Haman’s error was that he did it for his pleasure. Therefore, says the Chasam Sofer, on Purim we become intoxicated in a way that would have left no difference between Haman and Mordechai, L’Shem Shamayim. Just like Haman would have done Tzivui Hashem by killing the Jews had he done it Lishma, so too we must get drunk on Purim for the sake of fulfilling our obligation and not for our own pleasure. Or else there is an obviously vast difference between Haman and Mordechai, and we haven’t become shikorim K’halacha.