Trick or treat was an Earth custom in which costumed children traveled from home to home on Halloween, asking for treats such as candy with the question "Trick or treat?" The "trick" was a (harmless) threat to perform mischief on the homeowners if no treat was given.
After Montgomery Scott and Hikaru Sulu disappeared on Pyris VII and Jackson was killed there in 2267, Captain James T. Kirk said that, under other circumstances, he would wonder if someone were "playing an elaborate trick or treat." Spock did not understand the reference, but Kirk informed him he would be a natural, due to his Vulcan features. When Doctor McCoy later found himself chained up in a dungeon next to a skeleton, he reminded Kirk of his comment about trick or treat. McCoy went on to explain Spock's lack of understanding of trick or treat to Korob, who also did not understand the custom and dismissed it as being of no importance. (TOS: "Catspaw")
In the first draft script of ENT: "Fusion" (which had the working title "Equilibrium"), Trip Tucker voiced an indirect reference to "trick or treat" while explaining the traditions of Halloween to Fraht, stating that one of these customs was to "dress up in costume and go door-to-door" and that the purpose was to collect free candy. Tucker recalled that, after going trick or treating one year, he and his brother had eaten so much candy that they had needed to get their stomachs pumped at a hospital. Fraht at one point wondered if this was part of the custom, to which Trip replied that it wasn't.