Switching Headphone Jack
On the mechanical option for disconnecting speakers...

This is as old as the hills...probably 1960's. (An interweb search for '3.5mm socket changeover buy' leads you to some.)

1 is GND
2 is AmpL and normally connected to 4 SpkrL
3 is AmpR and normally connected to 5 SpkrR

When you plug the headphones in, 2/3 are sprung away from 4/5 to disconnect the speakers and are now connected to the headphones. Unfortunately, all of the speaker power is now being thumped into the headphones. If the headphones have a different/higher impedance to normal speakers, as they certainly do these days, it sounds trebley.



On the electronic option...

Here's an example circuit, showing one way of doing it. When the headphones are plugged in, the resistors pull the detect voltage to high and constant. This signals to the amplifier circuit to deliver a signal suitable for headphones.