What’s your explanation for how the move Trick-or-Treat works?
Hmm. Well, when you go Trick-or-Treat-ing, you “become” a ghost, or monster, or whatever, for a little while. You take a little journey into the spirit world, and gain new perspectives on the natural and the supernatural. Pumpkaboo is a Jack-o’-lantern, a light that guides souls through the spirit world, so it makes sense it would be able to get other Pokémon to follow it on that sort of escapade. Once you go along with that, you have some of the properties of a spirit yourself, including immunities and vulnerabilities.