At its very basic level - it goes back to the ancient peoples of Europe - particularly the Celts. They called it Samhain. It is basically a celebration, not only for the end of the Celtic year, but to honour their ancestors and family, friends etc. who had passed onto the next life.
When the Celtic tribes faded, it basically became warped over the centuries and all manner of things were brought into the festival to make it spooky and scary rather than an honourary festival for the dead and re-birth of a new year/life cycle. So in actual fact, although it is a fun time of year, the monsters, ghouls, hags and witches etc. have absolutely nothing to do with the real festival of Samhain. Although there are many people who still uphold the traditional festival of the Celts and use the time to honour those who have passed on. Samhain is much more complex than I've described, but it would need a full hub to do that. Hope this helps a bit.