How the MOSFET switch works A simple 'diode switch' passes whichever of 'mains' or PowerBank voltage is the higher. This is fine when we can guarantee (or set) the 'mains' voltage (when present) to be higher than the PowerBank voltage. However, a USB mains power block voltage is fixed and (whilst adequate) might well be less than the PowerBank voltage. This would mean Vmains is applied to the PowerBank at the same time as VpwrBank is passing power to the Pi - and since a low cost PowerBank does not support 'output' at the same time as 'input', at the very least you can expect it to 'glitch off'. We thus have to 'detect' Vmains and immediately 'switch off' VpwrBank. This makes for quite a complex circuit, because it's not just a matter of 'switching' whenever Vmains is present - instead we have to detect when Vmains is high enough to actually run the Pi. To control the PowerBank output, a (p-channel) MOSFET can be used. To enable the PowerBank the MOSFET Gate has to be driven toward 0v and to disable it, toward 5v. So if we wire Vmains input to the Gate, when the mains is absent (near 0v) the PowerBank will be switched in, and when Vmains is present (near 5v) the PowerBank will be switched out. Whilst this 'switches to Vmains' when the USB power-block is plugged in, there is a problem when the USB power block is unplugged. The MOSFET only 'switches on' when it's Gate voltage falls below the Gate-Source 'Vthreshold' voltage. With the Vthreshold of a typical 1A p-channel MOSFET - the NDS356AP - of about 1.6v, this means the PowerBank will only 'turn on' when Vmains drops below VpwrBank-1.6v i.e about 3.4v. Since Vpi will be Vmains-.3, by the time the MOSFET turns on, Vpi will have reached about 3.1v .... and the Pi will have crashed long ago. So it will be necessary to 'detect' when Vmains is 'too low' to power the Pi, and use that 'detect' to switch between Vmains and VpwrBank. The simplest way to 'detect' voltages is to use a Zener diode. If the Pi needs at least 4.75v and the (dual) Schottky diode voltage drop is .3v, then the 'detect too low' voltage will be 4.75 + 0.3 = 5.05v, so using a 5.1v Zener is 'safe'. To drive the MOSFET we can't just wire Vmains+Zener to the Gete. Instead an OpAmp is used to do the compare and amplify the difference (so the MOSFET Gate is switched rapidly from 0v to 5v). Since the OpAmp is powered from Vmains, we need to tie the MOSFET Gate to Gnd (so it turns on when the OpAmp is un-powered)
If the USB mains power block is unplugged when switch SW-1 is closed, the OpAmp will be un-powered and it's output 'hi-impedance', so R4 will keep the MOSFET Gate close to GND. This means the MOSFET will pass VpwrBank to Vpi.

When the USB mains power block is plugged in (irrespective of the SW-1 state) the OpAmp will power up. So long as Vmains is less than 5.1v, the Zener will not conduct. This means the '+' input of the OpAmp will be held to Gnd via R3. The '-' input, however, will rise to a voltage above Gnd set by the voltage divider formed by R1 and R2 (the actual voltage will be approx. Vmains/1000, however even this small voltage should be enough for the OpAmp to drive it's output to Gnd, and thus keep the MOSFET 'on').

When Vmains exceeds 5.1v, the Zener starts to conduct and the '+' input rises to Vmains-5.1. When the '+' input (Vmains-5.1) rises above the '-' input (Vmains/1000) = which will happen when Vmains exceeds about 5.11v = the OpAmp output will swing from Gnd to Vmains and the MOSFET will turn off.

With the MOSFET 'off', Vpi will be driven to Vmains-0.3 i.e. at least 5.11-0.3 = 4.81v. So long as Vmains stays above 5.1v Vpi will follow Vmains-0.3.

If the mains power block is unplugged, when Vmains falls below 5.11v the OpAmp output will swing from Vmains to Gnd and the MOSFET will turn on again. The Pi will remain powered by Vmains or the PowerBank until SW-1 is opened. Notes. 1) You will, of coure, require an OpAmp that works down to at least 3v (eg. LM358) or the MCP6001 (which operates down to 1.8v) 2) The MOSFET D-S 'body diode' has a Vf of about 2v, so can be ignored so long as Vpi is never more than 2v above PowerBank.