The very brief, I"m too lazy to google it version:
Short version is that it all goes back to the catholic church. In their designation of various saint's days they had marked Nov 1 as all saints day and Nov 2 as all souls day. When England became non-catholic they tried getting rid of all the catholic trappings (like saints) so all saints day became All Hallows day which made Oct 31 all hallows eve which morphed into halloween.
Somewhere along the way the belief that souls , spirits, ghosts, whatever could return to earth at that time became popular and people started dressing up like them thinking they would be less likely to harm one of their own kind than a human, and they also left gifts to try to bribe the spirits to leave them alone and not do them harm so that's the early origins of what morphed into trick or treating which yeah is basically an excuse for the whole community to buy and give candy to kids these days. Except for evil occult practitioners who do view it as a spiritually significant time of year.
And I remember that garfield special, I can still sing some of the songs from it.