As far as I know the two protocols are completely different, hence the electronics in the small case on one end.
Of course they're completely different. But every graphics card DP output port can change what signals it outputs.
There are two kinds of DP-to-HDMI adapters/cables: active and passive.
Active converters use an actual chip to read in the DP signal, convert it, and retransmit as HDMI. For a while, this was the only way to get 4K/60Hz HDMI output from DP, though newer cards with newer HDMI versions can do it with a passive adapter.
A passive adapter contains no electronics. It shorts some ID pins to tell the graphics card "hey, I'm a passive HDMI adapter" or "I'm a passive VGA adapter", which the graphics card reacts to by
outputting HDMI or VGA signals on the DP port. (These "alternate modes" were designed into DisplayPort from the start, so the ID pins and the pinouts of the adapters are standardized.)
DisplayPort's ability to switch modes is also how Thunderbolt works: it uses an alternate mode to essentially send PCIe packets over DisplayPort.
(Disclaimer: I'm not 100% certain on the official terminology and haven't looked it up.)