Many people customarily wear masks and costumes on Purim. Even though there is no source for this in the writings of the Sages, and the Aĥaronim did not write that one must wear costumes, various reasons have been given for the custom. The first reason is that it increases our joy, as a person with an unusual appearance can be amusing and entertaining. Another reason is that when one departs from his normal attire, he is able to let loose, rejoice, and display his love for his friends. Another reason is that having different modes of dress causes disunity among the Jewish people, and changing our external appearances on Purim breaks down the barriers between us and increases unity. Another reason is that by wearing costumes, we become aware of the degree to which we are influenced by external elements, and as a result, we can focus more on the internal elements that are revealed on Purim. Finally, costumes allude to the fact that even when the Jews look like gentiles on the outside, they remain Jews deep down, as the Purim story made clear.
Mahari Mintz writes that the custom in the homes of great and pious individuals in Germany was to dress up on Purim; men even wore women’s clothing and women wore men’s clothing (Responsa §16). He comments that one should not think poorly of them, since there is certainly no concern that this is prohibited. After all, the prohibition of lo yilbash (the prohibition against cross-dressing) refers only to wearing the clothing of the opposite gender for purpose of adultery and licentiousness. However, when this is done for the sake of rejoicing, it is not prohibited. Rema (696:8) writes that this is the accepted practice.
Most poskim, however, maintain that a man may not dress up as a woman, and a woman may not dress up as a man (Baĥ yd 182; Taz yd 182:4). Based on this, many Aĥaronim write that one should censure those who wear the clothing of the opposite sex. This is the correct practice. Some maintain that if a person changes only one article of clothing, and that person’s sex remains recognizable based on the other garments, one should not denounce him (Pri Megadim).