I went through this hoopla a while ago. Uncommanded switching to 4high and the last straw was also self switching to 4lo - quite a shock when it happens at 35mph.
Here's what I did that appears to have solved the problem:
I removed the encoder motor and checked the encoder ring for continuity. I also checked that the motor spins and didn't make any unusual noises. I also lubed the gearcase. After reinstalling the lights went haywire and service 4wd was on.
So I removed the encoder motor again and found no continuity in the encoder ring
Time for shopping at the PYP.
I picked up a 05 tccm and encoder ring. Installed them both in my 02.
It's been a few months and the problem has not returned. I still hesitate to say the issue is solved since the shifting happened randomly every few months. But it seems promising.
Some key points to note:
I removed both a 02 and 05 encoder ring. The 02 could be installed as is, but the 05 newer style ring had a high impedance oxide coating on the terminals that I had to sand off. I would suggest coating the terminals with dielectric grease to prevent the oxidation causing future problems.
And the 02-03 tccm is known to have issues, so while you're in the yard you might as well get one of those from an 05+ truck too and eliminate that from the potential cause of the problem.
Good luck!