A faster route uses parity instead of testing every two-digit number one by one. Write $n = PQ = 10P+Q$, so the sum of squares of $n$ and the number right next to it is $2n^2+2n+1$.
Notice $2n^2+2n+1$ is always an odd number, since $2n^2+2n$ is even and adding 1 makes it odd. The problem tells us this sum's last digit equals $P$, the tens digit of $PQ$. So $P$ must be odd: $P \in \{1,3,5,7,9\}$.
Since $(PQ)^2+(RS)^2$ has to stay a 3-digit number, $PQ$ and $RS$ must both be fairly small two-digit numbers, in the 10s or very low 20s (once a number passes the low 20s, its square alone is already close to or past 3 digits combined with the other square). Combined with $P$ odd, the only realistic tens digit is $P=1$, so $PQ$ sits in the 10s.
Now use the "distinct digits" rule. If $PQ$ and $RS$ are both in the 10s (like 14 and 15), their tens digits are both 1, so $P=R=1$, which breaks the requirement that all six letters be different digits. The only way to keep $P=1$ but give $RS$ a different tens digit is to let $PQ=19$ and $RS=20$, since jumping from 19 to 20 is the one place in the 10s where the tens digit actually changes.
Check this pair: $PQ=19$ gives $P=1,\ Q=9$. $RS=20$ gives $R=2,\ S=0$.
\[ 19^2+20^2 = 361+400=761 \]The last digit of $761$ is $1$, matching $P=1$ exactly, so $XYP = 761$ means $X=7$ and $Y=6$. All six digits $P=1,Q=9,R=2,S=0,X=7,Y=6$ are different from each other, so this is a fully valid, consistent assignment.
Let's summarize:
So $XYP=761$, which makes $Y=6$.