The phrase "trick or treat" might be a reference to the old Scottish and Irish tradition of "guising," during which children would go door to door performing party tricks for treats. These tricks often involved singing, telling jokes or reciting poetry; this could explain why "trick or treat" is said in a sing-song voice.
Halloween began in the United States to welcome immigrant settlers and act as a link to their heritage. The phrase "trick or treat" was not a part of Halloween originally, and there is no mention of it until 1927 in historic literature. However, it started being used frequently in the 1930s, and over time, it has become part of the tradition of Halloween.