Depends how long do you need to orient the weapon on the ship to damage it.
If you need the beam to hold for a long time (>1sec), or your using railguns:
I'd be looking at the accuracy of surveying tools like Theodolites. Here's one on eBay than can do 10 seconds of angular accuracy.
That's (10 / 60 / 60)'th of a degree. 0.00277778 degrees. That's about 5cm accuracy at 1km. 1m accuracy at 20km. It could hit a 100m ship at 2,000km.
That's just what the ebay one can do. Assume military grade is twice as accurate. I've found references to encoders able to do 5 seconds of accuracy. So a 100m ship at 4,000km.
If you only need to hit it with a laser for a fraction of a second, or pulses are fine:
We can measure time much more accurately than we can measure angles. So lets measure time instead and use time to measure the angles very precisely.
You can achieve incredible accuracy using rotating mirrors and a static laser fired at precise times to send pulses in exact directions. This is a process we use at my work to build laser scanners for surveying mines / crime scenes / car crashes / etc. You can use it to send gamma ray death beams nanoseconds long.
The process is to start rotating your mirror at a slow, steady speed, put the laser on at low intensity and record exactly when it hits a sensor (inside the gun housing). From that calculate the exact rotation speed and phase of the rotating mirror. If your mirror is doing 1rps, and your computer / sensor / etc is capable of running at 5ghz, you can turn the laser on and off very precisely at the exact angles you need - you can get your laser accurate to 0.000000072 degrees.
That's accurate to 1mm at 1000km. (Could probably do laser eye surgery at 1km). Hit the moons surface within 30cm. 1m accuracy at 1,000,000km. Hit a ship 150m in size in orbit around Mars from Earth orbit.