TITLE: Lattice points in a square pairwise-separated by integer distances
QUESTION [5 upvotes]: Let $S_n$ be an $n \times n$ square of lattice points in $\mathbb{Z}^2$.

Q1. What is the largest subset $A(n)$ of lattice points in $S_n$ that have the
  property that every pair of points in $A(n)$ are separated by
  an integer Euclidean distance?

Is it simply that $|A(n)| = n$?
And similarly in $\mathbb{Z}^d$ for $d>2$?

          


          

$5 \times 5$ lattice square, $5$ collinear points.



Q2. What is the largest subset $B(n)$ of lattice points in $S_n$,
  not all collinear, that have the
  property that every pair of points in $B(n)$ are separated by
  an integer Euclidean distance?


          


          

$5 \times 5$ lattice square, $4$ noncollinear points.


A $9 \times 9$ example with $5$ noncollinear points,
also based on $3{-}4{-}5$ right triangles, 
is illustrated in the Wikipedia article
Erdős–Diophantine graph.

REPLY [3 votes]: @FedorPetrov's idea leads in fact to the solution of Q1. It seems that it may also provide some progress for Q2, but this is beyond this answer.
I denote $[n]=\{1,2,\dots,n\}$; with standard conventions, we have $2[n]=\{2,4,\dots,2n\}$ and $2[n]-1=\{1,3,5,\dots,2n-1\}$. Let $A$ be a subset in $[n]^2$ with integer pairwise distances. We show by the induction on $n$ that

(1) $|A|\leq n$, and (2) if $|A|=n$, then $A$ is collinear in a line parallel to a coordinate axis. 

The base cases $n=1,2$ are clear. For the step, we use Fedor's observation that no two points in $A$ have opposite parities of abscissas and oppositve parities of ordinates. So we may assume all ordinates are odd. Now $A=A_0\sqcup A_1$, where the abscissas of the points in $A_0$ are even, and those for $A_1$ are odd.
Set $k=\lceil n/2\rceil\geq 2$. If $|A_0|, |A_1|\leq k-1$, then $|A|<n$, and we are done. Assume that, say, $|A_0|\geq k$. This means, by the induction hypothesis, that $A_0$ consists of all points with appropriate coordinates lying on some line $\ell$. 
Assume that $A_1$ contains a point $x$ outside $\ell$.  Then $A_0$ contains a $y$ such that both projections of the segment $xy$ onto the coordinate axes are segments of nonzero length, and one of those lengths is either $1$ or $2$. But there are no Pythagorean triples containing either $1$ or $2$ --- a contradiction. 
Hence $A$ is collinear on $\ell$, and $|A|\leq n$, as desired.