Per my understanding standard audio output through the headphone jacks is one-way communication. However if you plug headphones into the jack on a set of speakers it's the speaker's internal controll that is re-routing the audio. In the case of your setup the speakers are getting the audio via one-way communication from the jack on the back orf your computer and the headphones are receiving their audio from the jack on the phone of the system. The two jacks are taking the same audio but sending it down two sperate channels that do not communicate.
I do not know of a way to auto mute the audio in this case because they are being routed through seperate channels that do not pass data back to the system for connection verification. There may be a command-line script you can run to disable a specific port, but that you have to be manually triggered.
I am responding with my best thoughts about this, but I may be incorrect, I am hoping someone can pitch in and prove me wrong.