It started as a Pagan holiday. Or holidays, I should say. All Hallows Eve or Hallow e'en. And the costumes have their roots in a tradition of people dressing as the souls of the dead and going from house to house to collect alms for them.
The holiday was co-opted by the Catholic church and then it evolved into the secular holiday we have today. ...sorry....history professor.