It seems like either the vacuum system is erratic or the fork actuator is bad.
First try running with straight vacuum to the 4wd side and see if it still pops in and out. If not, then the problem is in the vacuum switch or the hoses to it. Truthfully you can leave that vacuum engaged permanently (mine has been left engaged for about the past 90K miles).
If the forks are dropping out, you can rebuild the actuator, replace with a manual lock, or simply physically lock the fork in place.
'89 Wrangler YJ
97 Grand Cherokee (ZJ)
87 MB 560SL roadster