On Celtic-Pagan influences; bonfires; JV Gods:
Celebrated as early as the 12th century, Samhain, which means “Summer’s end”, was a Celtic festival held around the end of October that marked the end of the harvest and the start of a “darker season”.
Darker seasons meant a) the sun literally wasn’t up as often, and b) the “Aos Si” (essentially JV gods, or spirits/fairies) were active and needed to be bribed with foodstuffs or they’d murder your cows -- so people would leave offerings. It was also a time when the souls of dead people not seen by Haley Joel Osment came back to their homes to hang out. To make them feel at home, people would light their nicer Yankee candles, say prayers, and then create huge bonfires, because dead souls are essentially just like drunk teenagers in fields.
After prayers, dinner, and fire with the dead souls, people would go out “guising” (e.g. wearing a disguise!) to fool or imitate the Aos Si (history isn’t clear on this distinction), often using the ash from those bonfires to blacken their faces, holding carved-out turnips (pumpkins are native to North America) with candles in them, and going door-to-door singing songs or reciting racy poems in exchange for food. If you didn’t give these weird people dressed up like JV Gods some of your Stouffer’s, they would threaten to do things to your home. So yes, in this version, trick-or-treating essentially started as a kind of f***ed-up blackmailing scheme.