In order to get to the minimum distance problem quickly, we quote a formula for the distance from the point $(x_0,y_0)$ to the line with equation $px+qy+r=0$. This distance is
$$\frac{|px_0+qy_0+r|}{\sqrt{p^2+q^2}}.$$
The site linked to gives a proof, as does Wikipedia. The distance from a point to a line has also been discussed more than once on StackExchange.
For our minimization problem, we can assume that one of the points is $(0,0)$, and the other is, say, $(a,b)$. So the line has equation $bx-ay=0$. We can assume that $a$ and $b$ are relatively prime, for if $d$ is their greatest common divisor, the same line is determined by $(0,0)$ and $(a/d,b/d)$.
Then by Bezout's Theorem, we can find integers $x_0$, $y_0$ between $0$ and $\max(a,b)$ such that $|bx_0-ay_0|=1$. Thus the smallest non-zero value of $|bx-ay|$ as $(x,y)$ ranges over our grid is $1$.
So the minimum possible non-zero distance from a gridpoint to our line is $\dfrac{1}{\sqrt{a^2+b^2}}$.
Now we want to maximize $a^2+b^2$, as $(a,b)$ ranges over relatively prime pairs on our grid. Then for fixed $a+b$, this maximum occurs when $a$ and $b$ differ by as little as possible. If $n=1$, the maximum value of $\sqrt{a^2+b^2}$ is achieved when $a=b=1$.
Suppose now that $n>1$. Then
the maximum value of $a^2+b^2$, given that $\gcd(a,b)=1$ and $(a,b)$ is on our grid is attained at $a=n-1$, $b=n$, and at $a=n$, $b=n-1$. The minimum non-zero distance is therefore
$$\frac{1}{\sqrt{2n^2-2n+1}}.$$
Comment: For our particular problem, we do not need Bezout's Theorem, since if $n>1$ then the distance from $(1,1)$ to the line through $(0,0)$ and $(n-1,n)$ is $1/(2n^2-2n+1)$. It is clear that we can't do better, since $|bx_0-ay_0|$ is at least $1$. However, if the $n\times n$ grid is replaced by an $m\times n$ grid, the natural analysis uses Bezout's Theorem.
Alright so here is one way of going about it (if I understood you correctly). So let $Z = (z_1,z_2)$ be the point lying on the line through $A,B$ such that the line passing through $C,Z$ is perpendicular to the line through $A,B$. You can find this point as follows.
We can find that $d(A,C) = \sqrt{104}$, $d(C,D) = \sqrt{(z_1-12)^2 + (z_2-10)^2}$, and $d(A,D) = \sqrt{(z_1-10)^2 + (z_2-20)^2}$.
So Pythagorean's theorem gives us the equation:
$$(d(C,D))^2 + (d(A,D))^2 = 104.$$
But we also know that $(z_1,z_2)$ is a solution to the equation of the line through $A,B$, namely the line $y= -\frac{13}{25}x + \frac{630}{25}$.
So now you have two equations and two unknowns. Give that a try and see if you can find $Z$. Once you have $Z$ you should be able to figure out whatever else you were wondering about.
Best Answer
The minimum $d$ is $\frac{1}{2\sqrt2}$, in the case you showed. The way to prove it is relatively easy. Choose four neighboring lattice points $(x_0,y_0)$, $(x_0+1,y_0)$, $(x_0,y_0+1)$, $(x_0+1,y_0+1)$ such as the line $y=ax+b$ goes in between. The distance from such a lattice point to the line can be written in terms of Pythagoras' theorem. We know the $x$ and $y$ components in the triangles formed by the lattice points, and the line. Along $x$ you have either $\{x\}$ or $\{1-x\}$ and along $y$ you have either $\{ax+b\}$ or $1-\{ax+b\}$ . Here the $\{\}$ notation means the fractional part.
We can write the areas of one of these triangles as either $0.5\{x\}\{ax+b\}$ or $0.5d\sqrt{\{x\}^2+\{y\}^2}$. From here $$d=\frac{\{x\}\{ax+b\}}{\sqrt{\{x\}^2+\{y\}^2}}$$ and similar combinations, with $\{x\}$ replaced with $1-\{x\}$ and/or $\{ax+b\}$ replaced with $1-\{ax+b\}$
Since we want to find the maximum distance for any line, it means that the $x$ and $y$ component are independent. The maximum value is reached when $\{x\}=1/2$ and $\{ax+b\}=1/2$. The minimum distance is then $$d=\frac{\frac{1}{2}\frac12}{\sqrt{\left(\frac{1}{2}\right)^2+\left(\frac{1}{2}\right)^2}}=\frac{1}{2\sqrt2}$$