It looks like it's related to other senses of the verb train. According to the OED, it comes from a Latin word which is cognate with the English draw and drag and which originally meant something like "to draw or pull along after one; to drag, haul, trail". From there more abstract senses developed like "to subject to discipline and instruction" and also the sense that you asked about, "to direct, point, or aim (a cannon or other fire-arm, or transf. a photographic camera)", which dates to 1841.
The noun and verb trail is apparently also related.