old wiring inside wall gets voltage when shared switch is used - safe and to code?
Presuming that the new wire (the constant hot) run to the fan is up to code, capping off the old wires in the metal fan box is fine.

You might consider also wrapping the wire nuts with electrician's tape for good measure.