The Shift motor has a Contact Wheel in the gear box than rotates when the motor turns the transfer case shift rod.
This Contact Wheel and its 6 contacts "tell" the Shift module what position the transfer case is in.
Pictures here:
http://www.explorerforum.com/forums/index.php?threads/how-to-rebuild-4x4-shift-motor.123542/
When you change from 2WD to 4high the Shift module powers up the shift motor and turns it counter clockwise until the CONTACTS are in the correct position for 4high
It does the same for 4low, and for 2WD it turns shift motor Clockwise until CONTACTS are in correct position for 2WD
It could be the contact wheel/contacts are dirty and just need to be cleaned, i.e. shift module "thinks" it is in 4high fully when it isn't.
And it could be the shift rod mechanism inside the transfer case is at fault.
With shift motor removed you can manually shift into 4high, use a pair of vise grips, and then tie them off so shifter stays put.
Then go for a drive, if it still pops out then you will need to get into transfer case, if it stays in 4high then rebuild and clean shift motor