Because it's not!
It's based on Samhain, a Celtic festival, it was a night thought to be when the veil between the world of the living and dead was thinnest, and people dressed up in order to fool those from the other side of the veil so that they wouldn't know they were alive and take them back with them.
Trick or treating came partly from that tradition. And also from souling, where people would pray for the dead in exchange for treats.
The other idea behind trick or treating was that by treating those that came to your door you would be blessed and be safe from the spirits.
As Samhain was seen as the end of the year (no more crops growing after that), it was also a way of ensuring you got through the winter safely, and were promised a good year after.
It is not an American import, we sent it over there first.