I originally assumed you were asking "How do you detect this via Linux files" or via a program, and not just via Desktop widgets. But in poking around my system, I couldn't find that response easily. Turns out a bit of googling immediately helped, and peeps to
this stack exchange question/answer.
If you were interested in via a program or a system file, check out
/proc/acound/card0/codec#0. What I did was concatenated that to a file in my home directory with no headphones inserted and a different file in my home directory after plugging in headphones and then compared the two files.
Obviously ALSA knows you did this action, and if you need to go deeper about how things are understood, then you'd have to grab the ALSA sources and determine where these changes are detected. My assumption is that it comes from the BIOS.