From the Super Mario Wiki
A spirit switch is an object from Wario: Master of Disguise. They are found throughout Blowhole Castle and affect the enemies that inhabit it. The spirit switches are off by default, and can be activated or deactivated by shooting them with Cosmic Wario's laser. While the spirit switches are off, most of the enemies in the castle are transparent, harmless, and unable to be defeated. Activating one of the switches causes them to solidify and become hostile toward Wario. In addition to affecting the enemies, there are numerous intangible blue flames found throughout the castle that turn into solid blocks when the spirit switches are on. The presence or absence of these blocks is necessary to reach certain areas of the castle, requiring Wario to hit the switches in order to make progress.