Basically derived from a Celtic holiday used to commemorate the end of summer and welcome the “dark” half of the year.
The witches, goblins, etc. is just extra crap thrown in for good measure and used to piss off the folks who see the devil in everything. It usually works too.
May the Celtic festival of Samhain be a happy one.
Goodbye summer. You bitch.