Trick-or-treating is a customary celebration for children on Halloween. Children often go in costume from house to house, asking for treats such as candy or sometimes money, with the question, "Trick or treat?" The word "trick" refers to a (mostly idle) "threat" to perform mischief on the homeowners or their property if no treat is given. In some parts of Scotland children still go guising. In this custom the child performs some sort of trick, i.e. sings a song or tells a ghost story, to earn their treats.
The practice of dressing up in costumes and begging door to door for treats on holidays dates back to the Middle Ages and includes Christmas wassailing. Trick-or-treating resembles the late medieval practice of souling, when poor folk would go door to door on Hallowmas (November 1), receiving food in return for prayers for the dead on All Souls Day (November 2). It originated in Ireland and Britain, although similar practices for the souls of the dead were found as far south as Italy. Shakespeare mentions the practice in his comedy The Two Gentlemen of Verona (1593), when Speed accuses his master of "puling [whimpering or whining] like a beggar at Hallowmas." The custom of wearing costumes and masks at Halloween goes back to Celtic traditions of attempting to copy the evil spirits or placate them, in Scotland for instance where the dead were impersonated by young men with masked, veiled or blackened faces, dressed in white.
So, as you see, Halloween has religious origins. Like many of our holidays, it pre-dates the Christian experience. But like others, it was “baptized” and transformed into a religious observance – and, sadly, like the same other holidays, continues to diminish its religious references in favor of commercial and secular understandings.
[Information gleaned from vairous sources including The History Channel]