Purim is a Jewish holiday to celebrate the Jewish people being saved from Haman. The tradition to eat hamantaschen on Purim appears to have begun in Europe. The name is derived from two German words: mohn (poppy seed) and taschen (pockets). Mohntaschen, or "poppy seed pockets," were a popular German pastry dating from medieval times. Around the late 1500s, German Jews dubbed them Hamantaschen, or "Haman's pockets." The play on words likely references the rumor that the evil Haman's pockets were filled with bribe money. Plus, mohn sounds like Haman. As with several Rosh Hashana food traditions, certain foods gained symbolic meaning, because their names sounded like words for qualities people hoped would characterize the year ahead.
What About Haman's Hat?
Another popular explanation for the hamantaschen's shape is that it represents Haman's three-cornered hat. These are often imagined as the "cocked hats" popular in Colonial America, or as Napoleon's distinctive topper. But these styles were not in fashion in Haman's time, and it's unlikely he ever wore hats like these. It's much more probable that over the centuries, as hats came into vogue that resembled hamantaschen, an association between Haman's alleged hat and the pastries was born.
Was Haman All Ears?
Another explanation for the Purim hamantaschen eating tradition is related to a Midrash (Jewish commentary on the Hebrew Scriptures) that describes Haman bent over and shamed, with "oznayim mekutafot" (the phrase has been mistranslated to mean clipped—or cut off—ears, though twisted ears would be more accurate).
In Israel, hamantashen are called oznei haman, which means Haman's ears. But originally, oznei haman referred to a different type of pastry altogether: fried dough drenched in honey or sugar syrup that was popular throughout the Sephardic world.
A (Literal) Play on Words
In The Encyclopedia of Jewish Food, Gil Marks notes that it's unclear when the name for these pastries evolved from oznayim (ears), as they'd long been known, to the Purim-specific oznei haman. Marks explains that the first known recorded example shows up in a 1550 play called Tzachut Bedichuta de-Kiddushin, An Eloquent Marriage Farce, a commedia dell’arte-style piece written in Hebrew by the Italian playwright and producer Judah Leone Ben Isaac Sommo. The play includes a debate about the logic of eating a food that symbolizes an evil enemy's ears; a second character responds that Jews are practically commanded to eat them, because the name of the pastries sounds like "manna"—which fell from the heavens to sustain the Israelites as they wandered in the desert following the Exodus from Egypt.
It's Not All About You, Haman
Another explanation for the popularity of the three-cornered pastry on Purim is cited in Alfred J. Kolatch's The Jewish Book of Why. Kolatch writes that Queen Esther derived strength from her ancestors, and the three corners of the hamantaschen cookie represent the three patriarchs (Abraham, Isaac, and Jacob). Others note that the popular poppy seed filling was a nod to Esther's vegetarian diet in Achashverosh's palace—she is said to have lived on seeds, nuts, and legumes, in order to keep kosher under the radar. And regardless of what's inside, the filling is partially covered by dough—just as G-d's role was veiled in the Purim story.
Historically, eating Haman's pockets, (or ears, or hat...) was meant as a way to symbolically destroy his memory. Today, they're usually seen as an iconic fixture of mishloach manot and the sugary fuel for raucous Purim festivities.