On Halloween, children in masks and costumes visit houses and ask for treats, using the phrase "trick or treat".
How did the tradition get started, and does it stem from the pagan festivals that inspired Halloween?
As I briefly mentioned in my answer on your other question, this too comes from the traditions of old.
Performing antics in exchange for food and drink. This practice is called mumming, from which the practice of trick-or-treating evolved.
This means that "trick-or-treating" once actually had to do with tricks. Not just a weird saying. More of an in-depth explanation comes from Today I Found Out:
beginning in the Middle-Ages, children and sometimes poor adults would dress up in the aforementioned costumes and go around door to door during Hallowmas begging for food or money in exchange for songs and prayers, often said on behalf of the dead ... ultimately gave rise to guising in the U.K. starting in the 19th century, with children dressing up and begging for things like fruit and money. In order to earn this token, they’d often tell jokes, sing songs, play an instrument, recite a poem, or perform in some other way for the amusement ... Trick or treating instead of guising on Halloween popped up in North America in the 1920s and 1930s, first in the western half of the continent. The term and the practice slowly spread, with a brief respite during WWII. After the WWII sugar rations were lifted, Halloween’s popularity saw a huge spike and within five years trick or treating was a near ubiquitous practice throughout North America.
You can look at the article to learn more.
Here is how the "trick or treat" of Halloween first caught on:
The phrase trick-or-treat was first used in America in 1927, with the traditions brought over to America by immigrants. Guising gave way to threatening pranks in exchange for sweets.
After a brief lull during the sugar rations in World War Two, Halloween became a widespread holiday that revolved around children, with newly built suburbs providing a safe place for children to roam free.
Costumes became more adventurous - in Victorian ages, they were influenced by gothic themes in literature, and dressed as bats and ghosts or what seemed exotic, such as an Egyptian pharoah. Later, costumes became influenced by pop culture, and became more sexualised in the 1970s. - What is the story behind Halloween and why do children trick or treat?