Welcome to the forum, willieandellen.
This could be a tricky one and there are differences between auto/manual and D21/D22/D40. I'm going to guess that it's a D40 since it's the only model with electronic control of the tranfer case. It's certainly an unusual problem.
My first thought is something to do with the neutral position switch in the gearbox. This activates when in neutral and the ECU restricts engine power output. The D40 doesn't often have trouble with its NPS but a faulty NPS usually leads to issues in the D22 with driveability. The common test (apart from disconnecting it) is to hold the gear lever to one side when it's showing symptoms. If the symptoms go away, it's the NPS and the simple fix is to unplug it, the remedy is to replace it.
However, there could also be a problem in the engine bay's power distribution box where the transfer case relays are. I'd certainly look in there if someone's been poking around at it to find a ignition wire for, say, a battery isolator or such.