Light guns have a sensor that registers when the electron beam sweeps by on the inside of the CRT (hence, they do not work on LCD screens, nor do they on 100Hz TVs as these do not flicker enough). The game registers the pulses from the gun and refers the time of the pulse with the known position of the beam and hence knows if the target has been hit when the trigger is pulled.
Basically.