As the CPU is drawing the screen, it makes all the targets on the screen white. The CPU notices the pulse from the light gun and stops the counter. The counter reads that the pulse was detected 15703.625uS after the counter started. That means that there have been 229 lines drawn down, and .25 of a line across. The CPU converts the screen position to something relative to the game world and checks for collisions.
Different hardware deals with the gun differently.
The SNES has an interrupt available that triggers on every scan line, so you can count lines by the interrupt and then just read the timer from the gun interrupt. The idea is basically the same though. I left out some stuff like differences in scan resolution to screen resolution, and hblank and vblank issues and overscan and whatnot, but hopefully this makes a bit more sense.