In America (and elsewhere?) we have a tradition of trick-or-treating where on Halloween or the night before kids go around the neighborhood in a costume, knock on doors, and get candy. It’s a lot of fun.
But I was well into adulthood before I learned that not all places have kids tell jokes before they get candy. Apparently it’s only the city I grew up in that they do that! Not even neighboring cities do it.
What you’re describing is (or at least was) the traditional way of doing Hallowe’en here in Scotland (and also in parts of England Wales and Ireland I think).
Trick or Treaters, more traditionally known as Guisers (because they’re in disguise) are/were expected to earn their treat with some jokes, or a song, or something.
It’s largely dying out now, such is the influence of Halloween (without the apostrophe) and especially the American version of it. Part of me is a bit sad about that, but on the other hand, it’s a hell of a lot simpler if people just hand over sweets instead of requiring a performance! Kids do still usually have at least one joke to tell though, which is fun :-)
See also this article on the pagan festival of Samhain, from which…