Identify 3 states at the input - Automotive circuit 24V system
I suggest a circuit like this:

R46 limits the current into Zener D5.  For 24V, that current would be (24-5.6)/1000=18.4mA.  Adjust values as desired.
R44 limits current into the ADC to protect against any transients.
I forgot the diode for reverse polarity protection.  R46 in series with the diode should protect it from excess current.
R121B1 and R121B2 can be higher, eg 100K.  Higher impedances will be more susceptible to EMI.
Please remember to mark as answer if this solves your issue.
Values are only guesses.  You'll need to do the math to make sure it hits the voltages you want.  Specifically R46 forms a voltage divider with R121B2 when pulling to ground, and R121B1 when pulling to 12/24V.
Make sure to set D5 to a voltage range your ADC can handle.