Halloween began as the festival Samhain. It was part of the ancient Celtic religion in Britain and other parts of Europe. At the end of summer, the Celts thought the varied between our world and the world of ghosts and spirits got really thin.
This meant weird creatures with strange powers could wander about on Earth. The Celts had a big party. It was all about scaring away the ghosts and spirits.
Also, they believed that as we moved from one year to the next the dead and the living would overlap and demons would roam the earth again. So dressing up as demons was a defence mechanism.