How to get rid of voltage spikes in this supply voltage switcher circuit?
Your output voltage is dipping because the power PFET is shorting the output node to the 12V supply that is at a lower voltage. Your threshold for turning on the PFET is much lower than 5V, effectively less than 1V.

I went ahead and remade your schematic in LTSpice:



The first question you should ask is "When does the NPN turn on?", which is practically immediately. There's a couple reasons for this:


Your NPN, a 2N3055, is a big, power NPN (15 A!!). You need maybe 1-3mA at most to turn on the PFET with the R3-R4 resistor divider. 
Because Q1 is so large, it really doesn't take much to turn it on a little bit. LTSpice has that transistor turning on at about 0.27V, which is probably less than you assumed.
I think you have your R1 and R2 values backwards. Even assuming a target VBE of 0.6V, your NPN would be on when the 12V rail was at 0.73V. The other way around, and it turns on at 3.43V or so (but probably lower).


Taking those things into account, we can see the voltages of the 12V rail (red), the NPN VBE (green), and the MOSFET gate voltage (blue). We can see the MOSFET turns on almost instantly. 



For more fun, here's a look at the DC sweep of V2 (the 12V supply) when V1 (the 5V supply) is held at 5.0V:



The current through D1 and M1 spikes to 27A, but really that's just what the diode model is limiting it to - the diode would probably blow up if the 12V supply was really an ideal source. The diode is only rated for about 1A. 

I'll admit, I'm not very fond of this topology, and I would probably look for a power management IC, or maybe some "ideal" diode ICs to handle the switching in a controlled manner. A comparator would be another solution. Keeping the 5V rail from back-feeding the 12V rail will be a bit tricky.

To tweak this topology, swap the 2N3055 for a 2N3904. Adjust the R1/R2 ratio to turn on Q1 when the 12V rail is above 5V. I'm pretty sure you don't need R4. The problem you will run into is that the behavior will be fairly sensitive to device variation (bad for products).