Why is Target Display Mode via Thunderbolt so unreliable for me?
Solution 1:
If you can touch the cable and have it drop in and out, I would say you either have a bad cable or bad connector (or both?) on one of the computers.
Try your setup with a different cable and see if you get the same result.
Good luck!
Solution 2:
I think it has to do with the timing. Did you connect your Thunderbolt cable before or after your iMac reached the login screen?
I do not know how target display mode is programmed, but I think all sound drivers on your iMac should be initiated first, before you connect the cable.
So when sound is not working, my simple solution is: CmdF2 out of target display mode, disconnect the cable. Wait a few seconds, reconnect is, CmdF2 back into target display mode. It does the job for me.
Next time, make sure your iMac reached the login screen and the hard drive isn't making much noise anymore before connecting your Thunderbolt cable.