It needs to be plugged in to the service diagnostic computer to see what possible error codes come up. Intermittent problems maybe caused by error flags in the diagnostic. It may cost you around $135 or more for a complete diagnostic. After all most automobiles these days are computer control.
I'm not sure what's causing it but I would definitely get it looked at, it passed because it's a intermittent problem hopefully they will be able to duplicate the problem and fix it before it gets worse and you get stranded somewhere.
What year is your car? I had a 03 s500 4 matic and that happened. Found out it’s a $1.00 plastic clip in the gear shifter that cracked. I waited too long to get it fixed and got stranded when it would not shift out of park. Dealer will only replace whole gear box and not clip. Paid about $2000 including labor to replace it. If that’s your problem find independent Mercedes mechanic that knows the problem and pay the Six hours labor and replace the plastic clip. It will save you at least $1500.
The vehicle needs to be checked out.
Thanks! Your answer is awaiting moderation.