Many many years ago mine did the same thing while it was still under warranty.
I would notice it was in the wrong setting even indicated it was in neutral sometimes, I took at back to the dealer and they reprogrammed it.
That lasted for a few weeks until it actually dropped from Auto to 4LO by itself while I was driving, I just heard a thump and almost kissed the windshield.
Good thing I was driving slow because there was about 3 inches of snow on the ground. The writeup guy said there was a bad seal on the transfer case encoder motor, but the bill said they replaced the transfer case encoder motor and they replaced the TCCM (Transfer Case Control Module)