Honorable Mention -- since, technically, it's not an episode of a regular series. It's the Great Pumpkin, Charlie Brown, October 27, 1966. This is the 1st animated depiction of 2 staples of the Peanuts comic strip: Lucy Van Pelt (voiced by Sally Dryer) pulling the football away from Charlie Brown (Peter Robbins), and Charlie's dog Snoopy (Bill Melendez) imagining himself to be a World War I flying ace.
Lucy's brother Linus (Christopher Shea), rather than Charlie himself, is the star of this episode, believing in the Great Pumpkin, apparently Halloween's answer to Santa Claus. Charlie's sister Sally (Kathy Steinberg), who has a crush on Linus, sits in the pumpkin patch with him, awaiting the Great Pumpkin's arrival. As for Charlie Brown's trick-or-treating, "I got a rock!"
Honorable Mention -- since it didn't air on or near Halloween (rather, it aired on New Year's Eve), but it does involve a costume party. The Honeymooners, "The Man From Space," December 31, 1955. Ralph Kramden (Jackie Gleason) and Ed Norton (Art Carney) both want to win the costume contest at their lodge, the Loyal Order of Friendly Raccoons. Their competitiveness causes a rift in their friendship. Ralph practically dismantles his apartment to build his "man from space" costume, and when Norton is called in to work in a sewer emergency, it looks like Ralphie boy has it won.
This episode would be shown in both the 1985 and the 1955 segments of Back to the Future. The Honeymooners did air on November 5, 1955, but it was a different episode, "The Sleepwalker."
10. Cheers, "Bar Wars V: The Final Judgment," October 31, 1991. Since Gary's Olde Towne Tavern, Cheers' arch-rival bar, has messed with them on Halloween before, and it appears that they have messed with Cheers on H-Day again, Sam Malone (Ted Danson) decides to go all in. It turns out that he and the Cheers Gang go too far.
9. Friends, "The One With the Halloween Party," November 1, 2001. The highlight of this episode is seeing Phoebe Buffay (Lisa Kudrow) dressed as Supergirl. But Ross Geller (David Schwimmer) dresses as "Spudnik," a potato with a silver TV antenna on his head, in tribute to the 1st artificial satellite, Sputnik 1. Except he looks like a giant turd.
8. Roseanne, "Boo!", October 31, 1989. Roseanne Conner (Roseanne Barr) likes to think she's "The Queen of Halloween." Her husband Dan (John Goodman), on the other hand, likes to think that he's "The Master." They go all-out to spook each other, and also to spook their daughter Becky (Lecy Goranson), who has lost the Halloween spirit.
7. Home Improvement, "Crazy For You," October 27, 1993. Tim "the Tool Man" Taylor (Tim Allen) is one of those perpetual kids who goes overboard for Halloween, including practical jokes, so his wife Jill (Patricia Richardson) decides to play a practical joke on him, convincing the local celebrity that he has a murderous stalker.
Till death do they part -- and then some.
5. Frasier, "Halloween," October 28, 1997. Dr. Niles Crane (David Hyde Pierce) hosts a Halloween party, with literary characters as the theme. He's dressed as Cyrano de Bergerac, complete with exaggerated nose.
His brother, Dr. Frasier Crane (Kelsey Grammer), discovers that his costume, the Archbishop of Canterbury from The Canterbury Tales, is "a babe magnet," particularly attracting a bodystocking-wearing Eve (played by Camille Donatacci, whom Grammer soon married).
But the subplot is that Roz Doyle (Peri Gilpin), the producer of Frasier's radio show, is pregnant (unplanned), but Niles misunderstands, and thinks Daphne Moon (Jane Leeves), his unrequited crush, is, and that the baby's father isn't stepping up to make an honest woman of her. So he proposes to her.
Frasier and Niles' father, retired Seattle Detective Martin Crane, is dressed as the greatest detective of them all, Sherlock Holmes. At one point, Niles asks him where Frasier is. Marty: "Haven't got a clue." Niles: "Holmes, you astound me!"
Meanwhile, we find out that Special Agent Tony DiNozzo (Michael Weatherly), a perpetual frat boy whom we would have expected to love Halloween, hates it. And forensic analyst Dr. Abby Sciuto (Pauley Perette) is dressed as Marilyn Monroe, and still helps to solve the case.
2. Castle, "Vampire Weekend," October 26, 2009. A college student who's into the "vampire lifestyle" is murdered in a cemetery. Mystery novelist Richard Castle (Nathan Fillion) and New York Detective Kate Beckett (Stana Katic) have to solve the murder. In so doing, they solve another murder, one from 18 years ago.
A subplot involving Castle's daughter Alexis (Molly Quinn) provides some comic relief, and finally some poignance. Castle starts out wearing what he calls a "space cowboy" costume, actually the one Fillion wore as Captain Mal Reynolds on Firefly, one of several references to that show over Castle's 8-year run. He ends it dressed as Edgar Allan Poe.
The song "Monster Mash" by Bobby "Boris" Pickett is a staple of Halloween episodes, but it wasn't recorded until 1962, 10 years after this M*A*S*H episode takes place, so it doesn't appear in the episode.