The trick-or-treat tradition evolved in the United States. Parents wanted to have an activity to keep their kids out of trouble. So, they started giving soul cakes, popcorn balls, etc. to kids in the neighborhood. Later, candy became more popular than soul cakes and other homemade sweets. So, kids started receiving those as sweets.