So you have established that both the headset and the phones are working as expected when connected to other devices.
I suspect the fault to be a kind of wear-in effect between socket and plug. The two parts would have their contact points always at the same locations. When you swap either part, they mate up with fresh contact points. Even if one side has wear, the new contact configuration is good enough to have a working connection.
Do the easiest thing first and have a very close look at the male bit of the headset. Use a magnifying glass and good light. Look out for any kind of marks.
If you find any, assume first they are dirt or verdigris instead of wear and try to remove them. Rubbing alcohol on soft cotton would be perfect to remove any greasy dirt. Verdigris is harder to get rid of. Don't worry about that now. Have another look.
Do the marks go away or get better? In that case it was just contamination.
Try if it works now or if it gets any better. Only consider cleaning the mating female contacts as well, if you were able to reduce/remove any marks on the plug. This is a lot harder as - obviously they are less accessible. You may want to think about having this done for you in a reliable shop where they (should) have experience ... and take responsibility if anything goes wrong.
I would not recommend cleaning the female contacts otherwise, because any dirt or verdigris on them should leave a mark on the mating male side as well. So if you have established that any marks on the male side are actual wear, assume the female side is clean and don't risk anything.
So they are not working yet? Next easiest thing to do is - use an extension lead. Actually I am assuming you don't have one and need to go and get one or otherwise you would have tried that earlier.
This should basically do the same as you did when testing the headset with another device and the phone with another head set. I admit this is not very elegant but at least it will prove the concept and you can listen to music again.
If there was wear on the contacts, don't expect this to last as long as a new setup. The wear is not going to get any better over time and now you have two potential points of failure. When that happens, you will be looking at replacing things. Consider if either plug or socket can be swapped before getting a whole new headset or phone.
Well, nothing lasts forever.
Based on the pictures you edited into your question:
Here is a suggestion that should keep you going until you get the new cable; it's a hacky one too :)
Your picture shows nicely where the socket contacts engage the plug and wore away the (gold?, cadmium?) galvanised coating. If you could find a washer of some insulating material that would fit over the plug you would shift the contact points downwards by a distance equal the thickness of the washer. The socket contacts would touch areas of the plug that are not worn.
I would think the washer wouldn't have to be so thick as to shift the contact area entirely into the unworn area. Something like 0.2-0.3mmm is probably enough. Don't make it so thick that the bottom contact ends up too near the ridge, or the engagement mechanism won't work any more.
Instead of a washer you might have a thin o-ring?
You could easily make something out of some clamshell packaging or similar plastic. You could even use cardboard which is available in different thicknesses. Try to make the center hole not too big, so it sits tightly on the plug, i.e. doesn't fall off when you unplug the cable.
Once you found something that works, but tends to come off, just use some glue to hold it in place. Obviously try not to get any glue on the contacts and make sure the glue is dry before using it, so you don't get any inside the socket.