There's ideal diode controllers like LM66200 which automatically switch between 2 sources, giving priority to the highest voltage :
https://www.ti.com/lit/ds/symlink/lm66200.pdfYou could add a diode in series with the internal voltage and that would lower it the internal voltage a bit below 5v, so when you insert the external 5v it would switch to that.
You can use a single ideal diodes like LM66100 and a p-channel mosfet to auto switch, without using a diode , see page 12 :
https://www.ti.com/lit/ds/symlink/lm66100.pdfMAX40200 is another ideal diode :
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX40200.pdfCould use it similarly ... have it on internal 5v with a diode before it to reduce the voltage a bit so that when you put external 5v the ideal diode will block lower internal voltage, or you could use it on external input along with a p-channel mosfet to disable internal voltage.
There are also chips that can switch between multiple inputs automatically but typically have limitations or are more expensive .
Look for example at TPS211, TPS2110, TPS2114, TPS2115 :
TPS2110/TPS2111 :
https://www.ti.com/lit/ds/symlink/tps2110a.pdfTPS2114/TPS2115 :
https://www.ti.com/lit/ds/symlink/tps2114a.pdf2115 is $2.65 if you buy just one on Digikey, while a LM66100 is maybe 40 cents and a p-channel mosfet is maybe 10-20 cents.
tps2113 is around $2
https://www.ti.com/lit/ds/symlink/tps2113a.pdfFPF3040 is cheaper at around 1.2$ on Digikey and does the same job but higher pin count chip and harder to use (bga balls) :
https://www.onsemi.com/pdf/datasheet/fpf3040-d.pdf Cheaper stuff, for example TPS22933 has 3 inputs and a built in 3.6v linear regulator and automatically switches between the input with the highest voltage. Downside is the output is maximum 50mA