Let the axes be X, Y and Z, and consider the 3 planes through P parallel respectively to the X and Y, X and Z, and Y and Z axes.
Let P(XY) be the point, if any, where L meets the XY plane, and S(XY) be the sum of the lengths of the two segments joining P and P(XY) in the X and Y dimensions. Define P(XZ), P(YZ), S(XZ) and S(YX) similarly. If L does not meet any one of the planes (ie it is parallel to the plane), ignore that plane.
Now let A and B be the axes such that S(AB) is the least of S(XY), S(XZ) and S(YZ). The corresponding point P(AB) is then the point Q in L that minimises the sum of the segment lengths from P.
To see that the sum of the segment lengths from P to any other point on L will be larger, note that, since L is linear, any such sum will be a positive linear combination of S(XY), S(XZ) and S(YZ), and therefore larger than the smallest of the three.