Hopefully its just in need of adjustment--there is a hole drilled in the shifter levers you line up with a drill bit with the linkages removed (I think in neutral),then you make sure the shift indicator lines up with neutral and you adjust the linkages to fit in the shifter levers,to adjust it..
Make sure all the mounts are intact (motor & transfer case to crossmember) and everything is bolted up tight too,that can make it pop out of gear--if its not just the shifter or that causing it,it could be worn detents in the shifting rail mechanism in the case,usually there is some type of spring loaded ball arrangement to "hold" it in the desired gear..could be excessive backlash in the gear train too..