In days of yore โsoulersโ (mainly children or the poor) would go from door to door on All Hallows Eve to be given soul cakes (think shortbread with spices) to commemorate the dead๐ฅฎ
Soulers would carry hollowed out turnip lanterns to represent a soul trapped in purgatory (the place you hang out before going to heaven or hell)๐
Replace turnips with pumpkins and add a generous helping of American commercialism and you get from Souling to Trick or Treat ๐ฌ