Thanks for your question.
More than likely the shift motor is the cause.
Sounds like the shift motor on the back of the transfercase is sticking. Double check that fuses are not blown, and connections to the transfercase is tight and clean.
Try this. Have the vehicle idling in neutral with the foot on the brake. Have someone inside the truck slowly activate the 4x4 switch while someone else is under the vehicle tapping on the shift motor with a hammer. Try this several times. If it then goes into 4x4 mode, replace the shift motor. What you're doing is trying to unstick the motor.