I love this metaphor. It reminds me of a specific tradition in tech criticism that treats (for instance) IoT devices as ‘haunted’ because, much like mythical hauntings, they are imbued with an alien will that is neither controlled nor easily understood by the owner. Your smart thermostat is a black box, doing things you don’t know about for reasons known only to the original developers (and sometimes known only to, like, the Mirai developers), and so unless you’re willing and able to disassemble and read its firmware and possibly reflash a modified version, the best way to treat it is as though you have adopted a mischevous (and possibly malevolent) imp.
This kind of illegibility is exactly what legacy code produces. The behavior is too complex to be analyzed (at least, in the time you have available), and so you’ve got no choice but to relate to it on the level of superstition. It’s not magic because it cannot be understood, but instead because you are not allowed the resources to understand it.