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")