Why is my key not coming out of the ignition unless I disconnect the battery?
My car has 120000 miles.
My car has an automatic transmission.
Your issue is very likely related to a component called a "shift lock". It’s a switch placed by the shift lever that only allows the key to be removed if the car is in park or neutral. This switch has to detect the shift lever is in one of those positions, and obviously is detecting otherwise. You will want to track down what is causing the miscommunication.
The first place to start is by checking the fuse box. You will have one or possibly two fuses related to this circuit. If both of those test good, the switch itself may need to be replaced.
One other issue that affect these switches is a physical obstruction. This can be caused by dirt, debris, or an object stuck in the area of the switch. The other way the switch can be physically obstructed is with a bent shift lever.
If you need some assistance with this repair, consider YourMechanic, as a certified technician can help diagnose the issue with your stuck key and help you make the necessary repairs.