Why must the p type be connected to the power source, and the n type be connected to ground?
They won't explode if you put the N-ch on the power source side. But you won't be able to open the mosfet (let it conduct) the usual simple way from GPIO. MOSFETs start to conduct (ignoring leakage current for this discussion) when there is enough voltage difference between Gate and Source - Vgs (Vg&gt;Vs for NMOS, Vg&lt;Vs for PMOS). For N-channel, Source is the &quot;lower&quot; side. And Gate has to be some 3V (depending on MOSFET) above the source in order for the MOSFET to be completely open (again, I use the word &quot;open&quot; in &quot;valve is open&quot; meaning - conducting).
So if you put N-ch on the high side, you need to apply 8V+ to the gate to open it for 5V power (because if it starts to conduct, the source will now also become 5V, and you need Vgate&gt;Vsource). You need excessive voltage, which you need to generate separately. If you put N-ch MOSFET between load and ground, the source of the mosfet will be at ground (0V), so you can apply 3.3V or 5V to open it directly from GPIO without extra voltage needed.
Same applies to P-channel. You will need to apply negative voltage to its gate (-3V or lower) if it's between load and ground, because you need Vgate&lt;Vsource.
N-channel MOSFETs have by nature slightly lower Rdson (resistance when conducting), and if that matters, you may actually use N-channel MOSFET on the higher side (and you drive its gate with higher voltage generated specifically for that purpose), but in absolute majority of the cases that is not necessary (and the difference is usually not that big; see datasheets - both PMOS and NMOS can have Rdson down to a pair dozen milliohms)
P.S. I tried to use as simple language as possible, I have cut a few corners a little for the sake of easy understanding. Check out some proper and more detailed explanations of how MOSFETs work.