Is abondoned wiring against code?

Okay, that came out funny. I’m not sure how to phrase this, but here’s an example.

Let’s say I wire up a light, and for whatever reason it’s not up to code. When I sell my house, the buyer notices that it’s not up to code and asks me to bring it up to code. Instead of starting over, I just remove the wires from the source and figure since there’s no power going to it, the NEC won’t apply to it. Is that true?

Okay, how about this. I remove the wires from the source, but also remove them from the light so it’s just a wire running through the house, but not connected to anything, is that a violation, assuming the way the wire is installed is up to code? What if it’s not?

PS, I’m just curious, I’m not planning to do this.

If the wire is dead (not connected to a possible power source and made impossible to re-connect) it’s not covered by the code.
When knob and tube or old cloth romex wiring is updated you can’t always remove all of it from the house so you blank up the j-boxes, cut the ends short, and pull out what you can and run new wire, but the old wire that is left is made to be unusable in the future (so nobody can tap into it later and re-energize it).

A home buyer or an inspector may still not like it or want it removed but that’s not a code issue anymore, it’s someone’s preference at that point.

Old wires must be removed or capped off in a junction box. You are not supposed to abandon wires. If you need to abandon wires and pulling them out or leaving an accessible junction box is not an option most inspectors will let it go as long as the wire is made inaccessible and could not be mistaken for a usable wire by the next electrician to come along.