Does your Mazda6 or CX-5 stay on (radio and displays stay on) after turning the car off?Then the issue is with your shifter switch. The car won't recognize ...
As suggested above, it could easily be a sensor switch related to shifting.
On a Mazda3, I had troubles reliably getting it out of (and sometimes into) Park. Turned out to be the brake sensor switch needing replacement. Another spot to look, if the shifter-area sensor(s) isn't the problem.