I’m going to try to explain the origins from memory so someone who knows more will probably explain better.
It comes from an book or a movie, where a husband is planning something nefarious (don’t remember if it’s a murder or something) and he uses the attic of his house to do it. This is set back in the days when they used gas for lighting things and when he turns on the lighting in the attic, it causes the lights to change (probably get dimmer) in the rest of the house. His wife notices this and brings it up to him, since he obviously doesn’t want to reveal that he is the one causing it, he constantly convinces his wife that it’s all in her head and that she might be losing her mind.
I’m actually kinda impressed