Well intermittent problems are tough for a mechanic because when he's there, the problem isn't.
I think he's on the right track---something is quirky with the shift-interlock solenoid system. Also you could have a glitch in your brake light switch---if that doesn't work properly the interlock will not get the signal to release the solenoid. You can always release the gear shift by inserting a screw driver into the slot provided next to the shifter. This would help you get unstuck at least.
The system might have to fail completely before it can be fixed---otherwise all you can do here is replace parts and see if it goes away. Have you tried multiple pumps on the brake pedal when this happens? If that clears it up, then I'd suspect the brake light switch or its connections.