When redoing the wiring for one reason or another, it's trivially easy to peel the switch off with a screwdriver and remove the glue.
There isn't a compellingly better way of attaching that switch there. It has mounting screw holes but they point in the wrong direction, into the cavity. To screw it down, I would need some sort of long risers that somehow attach to the bottom of the cavity and are firm enough to resist the side to side push. Little L-brackets could work that attach to the side of the cavity. It's a very small cavity: hard to screw such brackets in, but that can be solved. Even if the brackets themselves were permanently mounted, not having to be removed when the switch is taken out, it would still take more time than with the glue.
Another use I have for glue is to secure a household internet connection. It's just a thin wire coming out of a RJ jack in the wall, in a room where kids play. The installer didn't crimp the plug into the cable insulation. The situation is that the insulation ends a few millimeters before the RJ plug, leaving a couple of bare wires that seem like 22 AWG crimped in. I "kid-proofed" this with hot glue. Hot glue is all over that plug, and about two feet of the cable is basically encased in hot glue, attached to the switch plate and along the wall right until the point it goes behind some furniture. I check on it from time to time to repair any tearing away.
Which ones have this property, and which ones do not? How do we tell them apart?
How do I identify the cheap hot glue that came with the cheap hot glue gun that I bought at Dollar General on a Saturday afternoon in 2021? It does this business just fine.