Switch between two power supplies
First of all: add a capacitor in parallel to your load. Every switching operation will inevitably lead to some short disruption, and a sufficiently sized capacitor will allow your device to continue working through the switchover.

Then, as M D said, you could just have a microcontroller on the load side of things that monitors both power sources and initiates switching when necessary. How that switching is done, and what "necessary" means in this context, is up to you to define.

Furthermore, this is often solved by using dedicated circuitry, since it's a very common problem and needs a fast and reliable solution in many cases.

So, companies like Linear Technologies have ICs that do that – the LTC4412 has an especially nice datasheet with examples of how to use it to control a MOSFET to do your switching.