The general practice of going door-to-door for treats is clearly similar to a much older practice, “souling,” in which the poor would go from house to house begging for alms or food. However, the specific practice of “trick-or-treating” dates to around the 1930s. It is possible—though by no means certain—that it evolved as an antidote for the increasingly rowdy and costly Halloween pranks. It provided a healthier activity for the young and gave them an incentive not to play tricks.
We could easily make something up about the origins of Halloween costumes. We could say that people originally dressed as ghosts and witches to scare people, and that the practice eventually spread to include costumes of all sorts. But the fact is that we don’t actually know where Halloween costumes came from, only that the practice, like trick-or-treating, appears to have begun in early 20th century America.