Although this was traditionally hardware (or perhaps some firmware burned permanently onto a ROM somewhere) on modern hardware it is more often software. There are a mind-boggling variety of possible ways to have things work, and as usual in the PC industry and in embedded systems the manufacturers have chosen "all of the above" occasionally even on a model by model basis.
So there may or may not be multiple outputs, it may or may not be possible to drive more than one at once, and they may or may not be physically capable of being driven at different levels (ie independent volume controls), and each may or may not have, require or support a separate PCM stream, and the physical hardware ports used may or may not be re-used between configurations including more than two speakers ("home cinema") microphone or line in.
The ALSA drivers may, or may not, enable some or all of these features on specific hardware depending on whether somebody got the hardware reference sheets for the chipset and for the specific implementation (a lot of these chips have a handful of GPIO pins whose purpose of course the PC makers feel free to change on a whim) and then PulseAudio may or may not make use of the features exposed by ALSA.
I think that ALSA has in some cases done the work of switching amplifiers on and off automatically on jack detection, but this work on PulseAudio means that PA will notice the jack insertion too, so that my desktop volume settings (which I currently must turn up when using speakers and then quickly turn down if I plug in headphones) might some day soon Just Work™ remembering how they were set when I last had things plugged in this way.
Another cute thing you can do in userspace is demonstrated by Android (and most similar phone software, but Android is Linux-based and I happen to have an Android handset to verify this). When you unplug the headphones from a device, it may make sense to pause playback rather than move the sound to speakers.