In the 19th century, “tricks”—such as rattling windows and tying doors shut—were often made to look as though supernatural forces had conjured them. Some people offered candy as a way to protect their homes from pranksters, who might wreak havoc by disassembling farm equipment and reassembling it on a rooftop. By the early 20th century, some property owners had even begun to fight back and lawmakers encouraged communities to keep children in check with wholesome fun. https://www.nationalgeographic.com/culture/article/the-history-of-trick-or-treating-and-how-it-became-a-halloween-tradition