Halloween used to be a very rowdy and dangerous event (look up 'gate night' or modern 'devil's night') after one especially bad year, "Black Halloween" in the mid 1930s, people looked for calmer, safer alternatives.
The phrase 'trick or treat' first appears in the late 1930s and it was one of the safer alternatives, giving children treats if they behave (also things like costume parties with adult supervision began in the 1930s).
When I was a child, trick or treat was a lot of fun, you waited until after dark and plunged into the night by yourself (or other kids you met along the way). The best treats were homemade things like candy apples or popcorn balls or rice krispie squares.
Various events (and urban legends) and corporate actions removed the homemade items and the time for trick or treat became earlier and earlier as helicopter parents appeared and now it's almost entirely in the day time (often on a specified day, not Halloween and adults tag along the entire time) and it seems dreary and lame.....
ghetto chile does? Since their neighborhood sucks
Where I grew up the town was segregated and so was trick or treating. But black kids always had the best hauls (you brought candy to school to trade) because they had a community behind them while we just went to random houses of people who didn't know us. Any time there was a fund raising competition the black kids always won for the same reason -- they had strong social networks.
All that's lost now....