Detecting TVs with PC's graphics card
The answer is on Wikipedia should you care to ask google:


  Non-standard 7-pin mini-DIN connectors (termed "7P") are used in some computer equipment (PCs and Macs). A 7-pin socket accepts, and is pin compatible, with a standard 4-pin S-Video plug. The three extra sockets may be used to supply composite (CVBS), an RGB or YPbPr video signal, or an I²C interface. The pinout usage varies among manufacturers. In some implementations, the remaining pin must be grounded to enable the composite output or disable the S-Video output.
  
  -- Wikipedia


So some systems can use a (not part of the official S-Video spec) I²C interface in the same way that VGA interfaces use I²C to identify the monitor connected.

For other setups, where it just detects the presence of a screen, it is as simple as measuring the impedance (75Ω) at the remote end of the connection. A simple enough thing to arrange.