It is not wise to operate a solenoid for a long period of time off a battery, small pulses are OK if you mitigate the other issues
Batteries have an internal resistance, for short duration pulse loads you can treat them like a power supply with a resistor between the supply and your load, this means drawing a large amount of current will make the voltage on your load decrease, and generate some heat in the ESR / resistor,
The value of this ESR tends to get worse as the battery depletes, and changes with temperature,
This is making some assumptions, but lets say your solenoid resistance is about 22 ohm (9V / 0.4A), a 9V battery is normally 1.5-5 ohm ESR for the first 50% of its capacity
For your solenoid, you could on a proper supply work out what its "Actuation Voltage" is, e.g. what voltage is the minimum to make it unlock, this tells you how low the voltage can droop before it stops working
As for why your circuit stopped working, that is harder to say, its possible the nductive spikes carried into the rest of the circuit, (This is why circuits have decoupling capacitors and reverse polarity diodes across inductive loads)