Q: What is the origin of giving candy for Halloween?
Halloween, like so many holidays, was originally celebrated by ancient pagans. Its purpose was to honor the autumn harvest and usher in the dark winter months. This festival was the beginning of their new year, so essentially, Oct. 31 was the pagan New Year's Eve. Many interesting rituals (none of which are satanic or evil) surrounded this holiday, including a festival of fire in which community bonfires were ignited for villagers to gather from in order to light their hearths for the coming year. This was also a time to celebrate the continuity of life: People believed that the doors between the world of the living and the dead were set ajar, allowing spirits to pass freely back and forth. The souls of those who had died in the previous year could now effortlessly pass to their final resting places.
Halloween is still celebrated in much of the western world, albeit in a much-adapted form. In its original birthplace of Ireland, Scotland and Wales, they celebrate much the way we do in the United States. In Mexico they celebrate Dia de los Muertos (Day of the Dead) in the November days following Halloween.
But to answer your question: The tradition of giving away candy on Halloween seems to have stemmed from an ancient tradition of leaving food and drink outside the home to nourish spirits as they wandered. As villagers passed from house to house sharing in the festivities, masks were worn to scare away any spirits that were evil.
As time passed, the Christian Church appropriated the holiday as their own by declaring Nov. 1 "All Saints Day" and encouraged their followers to give currant bread to beggars in honor of dead saints. These traditions were brought with Irish and Scottish immigrants to America, and over time the food for spirits that became cakes for beggars eventually turned into candy for firstname.lastname@example.org