Ghosts and goblins were all over the place. The Celts had to protect themselves.
If the Jack-o-lantern didn't scare off the spirits then they had their gift of food (a treat).
If that didn't work there was one last resort.
If you wore a really, really scary costume you would look like a demon or a spirit. That way none of the ghosts would pick on you.
That is how wearing costumes started.