Sounds like a linkage prob. to me also ....
Are the body mounts good ?
I had a K5 that would act up ( no 4WD , no 2WD ) with no warning , found that the body mounts were rusted away and the body would roll slightly in a turn and pull the transfer case linkage enough to pull it out of gear. i first lengthened the linkage to fix the problem but after beating the hell out of it off road I ended up having to just put it in 4WD and then disconnect the linkage

God I miss wheeling a full sized rig , but they kinda piss off the tree huggers from time to time .
I would suggest you disconnect the linkage at the transfer case and manually put it in 2WD and drive it around . see if you have any problems . then manually put it in 4WD and repeat . if you don't have any problem then you have narrowed it down to the linkage or shifter.
Just remember to do this while on flat ground with the wheels chocked !!!