Switching a solenoid between 2 different AC/DC adapters?
I'd consider doing it this way: -



There is a P channel FET used to switch either the 9V or the 24V. Note the extra 10k resistor (circled in red) in series with the FET gate - most FETs can have several volts on their gates but 24V is too much and so I've limited it to about 12V with the resistor.

Also circled in red are schottky diodes. These are protection but the one in series with the 24V output may not be needed and can be replaced with a short circuit. The one in series with the 9V is needed because when the 24V supply activates it doesn't want to be driving current into the 9V supply switch - the schottky diode prevents this by reverse biasing when 24V is present.

The "optional schottky" is to stop reverse currents into the top P channel FET should the 24V supply become disconnected whilst the 9V is activated. It is removable should you feel there are no circumstances that warrant this.

Controls are circled in blue (MCU #1 and #2) - the logic levels can be 3V3 or 5V. Also note the 1N4001 diode across the solenoid to prevent voltage spikes damaging the devices when the solenoid is switched off.

I've assumed that the max current thru the solenoid is 1A - if it is greater than this then maybe consider going for a more powerful diode than the 1N4001 but it should be OK providing you are not switching this circuit on and off rapidly and repeatedly.

I've not listed the P channels FET but use one that can handle the current of the load and is rated no-less than 30V. The schottky diodes also need to be rated with max reverse voltage greater than 30V and current rating should be as per the solenoid's requirements with a little headroom of course.

The down side of this circuit is that the 9V supply is realistically dropped to about 8.5V due to the lower schottky and should you decide the top schottky is required the 24V supply will be more like 23.5V

EDIT - here's a FET I'd consider using. It can easily switch the load and is rated at 30V and can even tolerate 25V on the gate (I'd still use the 10k resistor though): -