We had a 3 series that would do this. ( Wonder why I got such a deal at the auction).
After kicking our techs butt's they declared it fixed and I took it on a road trip. At 5 in the morning it started doing this and I finally got off the freeway. An old local guy came up, asked what I was doing and told me a story about a peagot ( not mis-spelled, his pronounciation) doing this. He said the battery had plates loose and would short on bumps or turns.
I changed out the battery and it solved the problem.
89 525, 86 jetta diesel, 07 wrx with mods, 06 commander
1 mean wife, 2 daughters, 1 bull mastiff. At least the jetta
is cheap to keep up.