L298N Module 5V pin behavior on above 12V power supply
The module you are using has an LM7805 5V regulator on board.  It will provide 5V as long as the input stays above about 7.5V.  Your 12V battery should never drop that low.
You can use the module as planned with your 12V battery without worry.

The 5V output doesn't &quot;switch&quot; depending on the input voltage.
If you supply 12V to the module, it makes 5V using the LM7805.
If you disconnect the 12V input, you can put 5V into the module on the 5V line.
Switching the 5V from output to input is something you must do.  It can't do it itself.