I would argue, though, that the Phaser marksmanship we witnessed in TOS was a by-product of limited special effects technology and script conventions.
Certainly so - but most of the Trek universe is the direct result and product of such limitations. The very existence of transporters is a VFX budget conceit; we shouldn't dismiss transporters for that.
Look at Kirk's phenomenal marksmanship in "Errand of Mercy". He picked-off that Klingon at an extended distance.
And had time to let his auto-aiming doodad do some precision work beforehand. One wonders, though... Are stun beams easy in that respect, with coarse aim and wide beams producing the intended results while a coarse aiming of a wide vaporization beam would just court disaster?
As for how the phasers do that exactly, we don't really need to know beyond the fact that we can do it today - they just do it better in the future. A simple camera (although no doubt hyperspectral in Trek) can analyze the image (with much greater and cleverer computing resouces in Trek) to spot the target and cue the user or the weapon, stealthily and passively. Although how much value stealth at aiming would add to phaser use is debatable, considering the shot itself gives the shooter away in any case.
Timo Saloniemi