As recently as when I was a child (not long ago in the history of the world), there was an implied menace to the custom, at least in the U.S. The expression stood for a kind of extortion. It meant “Give us a treat or we’ll play a trick on you”—and it could result in some kind of mischief, not always innocent, such as papering your yard or soaping the windows of your car. I can remember my parents keeping nervous watch for roving boys who might be up to no good.
Meanwhile, the neighborhoods were deemed safe enough for little kids to go about in costume collecting treats without any adults accompanying them. Treats were often homemade, and there was no fear of harm or contamination. Life was simpler then.
The holiday itself, All Hallows’ Eve, is a very old one with its roots in ancient Celtic beliefs and superstitions. You can read one account of it here and find many others if you look around.