Those of us who grew up in trick-or-treating times took for granted how much trust and hospitality it took at the community level for the ritual to thrive.
On the kids' side, both they and their parents had to have enough good faith in their neighbors to venture out in the first place. I don't mean that otherwise they might suspect their neighbors of slipping them poisoned candy, apples with razor blades inside, etc. I mean they had to trust that their neighbors would be hospitable enough to buy bags of candy and be on-call that night to hand them out. When people get more cynical (probably the parents here more than the kids), they'll just assume, "Well our neighbors don't give a shit about hospitality anymore, so why bother sending the kids out?"
That creates a positive feedback loop that makes the remaining neighbors drop out too. As fewer kids are sent out each year, a participating neighbor sees that there's less and less of a point to buying candy and waiting near the door, dressing up themselves, and so on. At some point they just keep the front lights off and don't get up to answer the rare knock at the door.
What do the candy-givers get out of the exchange, by the way? It's not a parasitic relationship. They receive the joy from knowing that they belong to a cohesive community -- proven by the fact that all the parents nearby have trusted them to host their kids for a night. The parents back home receive the same joy; obviously they don't get any candy themselves. This is why people participate in any "rite of intensification," i.e. one that confirms and strengthens the feeling of group membership.
However, with fewer neighbors participating, the kids and especially parents are more likely to feel it would be pointless to go out, so they stay home instead. Before long, there are no more trick-or-treaters or candy-givers, everyone believing that everyone else is just too anti-social for the reciprocity to work.
That's more or less what took place from the mid-'90s through today, not coincidentally when all forms of togetherness began dying off. Google Ngrams shows that "trick or treat" shows up in books starting in the 1950s, and really got going during the '60s, when the phrase "trick or treating" also caught on. The golden age of trick-or-treating was of course the later '70s through the early '90s, when we enjoyed two related but independent sources of cohesion -- the peak of our national eminence that lasted from the '50s through the '80s, and the more local protective bonds caused by the rising crime rates from the '60s through the '80s.
I don't know what it felt like on the kids' side (or their parents) as trick-or-treating died off, since the last time I went out was '91 or '92. It must've felt disappointing to hear "Oh, sorry, we didn't buy any candy this year" with each passing Halloween.
But I sure do remember how demoralizing it was on the candy-givers' side. I started passing out candy when I was in 8th or 9th grade in the mid-'90s, and kept at it through high school. The number of kids just plummeted during that time. When I gave it another go last year, there was exactly one kid who stopped by, and I was outside and would've seen anyone else who walked on by.
I somewhat miss the fun you get from scaring little kids before lighting up their faces with a big stash of candy. The really depressing thing, though, was the awareness that no one in my so-called community trusted me or anyone else in the neighborhood to host their kids for a couple hours. Naturally as a thin-skinned high schooler I took that personally, but now I see that it's just part of the larger dissolving of community bonds, along with the disappearance of babysitters, not going to church, and home-schooling.