If the manufacturer doesn’t offer a specific command for that via IP or IR, which we believe is the case for Samsung TVs, you would need to bring the audio control out of the Samsung to resolve that via control. For instance, one way we hook that up is by using a small/cheap receiver that doesn’t even have speakers connected to it. For instance an Onkyo 616 is something we’ve used for this purpose. Hook the headphones up to the Onkyo. The Samsung is fed HDMI from the Onkyo. Whatever your input source is also gets connected to the Onkyo. When you want to switch to headphones, send HDMI AUDIO OFF. When you want TV Speakers, send HDMI AUDIO ON.
There are of course various other ways of configuring a solution for that, but we like the above because it lets the headphones get switched entirely via the control system rather than the common solution of needing to plug the headphones into the front of the receiver in order to activate them every time.