You already have
$$q^2-q+1=pk\quad\text{and}\quad p-1=k(q+1)$$
where $k$ is a positive integer.
Eliminating $p$ gives
$$q^2-q+1=(kq+k+1)k,$$
i.e.
$$q^2+(-1-k^2)q-k^2-k+1=0$$
to have
$$q=\frac{k^2+1+\sqrt{k^4+6k^2+4k-3}}{2}$$
Note here that we get, for $k\gt 3$,
$$k^2+3\lt \sqrt{k^4+6k^2+4k-3}\lt k^2+4$$
from which we have to have $k=1,2,3$.
For $k=1$, $\sqrt{k^4+6k^2+4k-3}=\sqrt 8\not\in\mathbb Z$
For $k=2$, $\sqrt{k^4+6k^2+4k-3}=\sqrt{45}\not\in\mathbb Z$
For $k=3$, $q=11,p=37$.
Hence, $\color{red}{(p,q)=(37,11)}$ is the only solution.
if $2^a+5^b=w^2$, then $2^a \equiv w^2 \pmod 5$. This implies that $2\mid a$. So let $c\in\Bbb{N}\space|\space 2c=a$.
$$2^{2c}+5^b=w^2$$
$$5^b=w^2-2^{2c}$$
$$5^b=(w-2^c)(w+2^c)$$
both $w-2^c$ and $w+2^c$ are both powers of $5$ so $\exists \space s,t\in\Bbb{N}\space|\space b=s+t, s>t,\space 5^s=w+2^c,5^t=w-2^c$
$$5^s=w+2^c\space\space\space(1)$$
$$5^t=w-2^c\space\space\space(2)$$
subtracting $(2)$ from $(1)$ we get
$$5^s-5^t=2^{c+1}\space\space\space(3)$$
$$5^t(5^{s-t}-1)=2^{c+1}\space\space\space(4)$$
$5\nmid 2^{c+1}$ so $t=0$ and $s=b$. Therefore
$$5^b-1=2^{c+1}\space\space\space(5)$$
$$5^b-5+2^2=2^{c+1}\space\space\space(6)$$
$$5^b-5=2^{c+1}-2^2\space\space\space(7)$$
$$5(5^{b-1}-1)=2^2(2^{c-1}-1)\space\space\space(8)$$
$5\mid $lhs of (8) $\Rightarrow$ $5\mid $rhs of (8). $5\nmid 2^2$ so $5 \mid 2^{c-1}-1 \Rightarrow 4 \mid c-1$
lhs of (8) $\equiv 0,20,27\pmod {31}$ and rhs of (8) $\equiv 0,4,12,28,29\pmod {31}$
The only way for the equation to be equal is if both sides are divisible by 31.
$31\nmid 2^2$ therefore $31\mid 2^{c-1}-1 \Rightarrow 5 \mid c-1$
Combining both of the facts that $4 \mid c-1$ and $5 \mid c-1\Rightarrow 20\mid c-1\Rightarrow 25 \mid 2^{c-1}-1\Rightarrow 25\mid $rhs of (8)$\Rightarrow 25\mid $lhs of (8) $\Rightarrow 5\mid 5^{b-1}-1\Rightarrow b=1$
plugging in $1$ for $b$ in $(5)$ implies that $c=1\Rightarrow a=2$
the first solution is $a=2$, $b=1$, $w^2=9$
Edit: In the beginning of the proof I assumed that $2^a\equiv w^2 \pmod 5$. This is true iff $b\neq 0$.
If $b=0$ then $2^a+1=w^2$
$$2^a+1=w^2$$
$$2^a=w^2-1$$
$$2^a=(w-1)(w+1)$$
both $w-1$ and $w+1$ are both powers of $2$ so $\exists \space u,v\in\Bbb{N}\space|\space a=u+v, u>v,\space 2^u=w+1,2^v=w-1$
$$2^u=w+1\quad(9)$$
$$2^v=w-1\quad(10)$$
subtracting $(10)$ from $(9)$ we get
$$2^u-2^v=2\quad(11)$$
$$2^v(2^{u-v}-1)=2\quad(12)$$
This implies $v=1$ and both sides of (12) can be divided by 2
$$2^{u-1}-1=1\quad(13)$$
$$2^{u-1}=2\quad(14)$$
$$u-1=1\quad(15)$$
$$u=2\quad(16)$$
This gives the second solution $a=3$, $b=0$, $w^2=9$
Edit 2: too long for comment, answering Prathmesh's question from the comment below
After getting to equation to $(8)$ I knew that if I could show that $5 \mid 5^{b-1}-1$ then there would only be one solution to that portion of the problem. Working backwards $25 \mid 2^{c-1}-1$. powers of $2$ have a cycle of $20 \pmod{25}$. So $25 \mid 2^{c-1}-1$ iff $20 \mid c-1$. I already had $4 \mid c-1$ from the fact that both sides of $(8)$ are divisible by $5$. So I needed a mod that produces cycle that is a multiple of $5$ in powers of $2$. In general if a mod will produce a cycle $x$ if the mod is divisible by a sufficiently large power of of $x$ or is divisible by a prime factor that is of the form $xk+1$. So the mod in this case needs to have a sufficiently large power of of $5$ or has a prime factor of the form $5k+1$. Since I am trying to prove that the rhs is divisable by $25$ I can't use powers of $5$ so I am left with numbers that have a prime factor of the form $5k+1$. All primes except $2$ are odd so I can just look at numbers of the form $10k+1$. So I first tried $11$ but both sides can be $\equiv 1,3,4,5,9\pmod{11}$. $21$ has a prime factorization of $3$ and $7$ neither of which is of the form $10k+1$. so then I tried $31$.
Best Answer
It's not a complete answer, but as mentioned in comments, this problem probably missed some restrictions, and so have too many solutions. Thus I decided to answer this question for the case that $f$ have constant value in infinite (or finite by little changes) partition of $\mathbb N$.
I expect another answers for remained cases e.g when $f$ is an increasing function (polynomial case mentioned in comments).
Let $A$ is an infinite subset of $\mathbb N$, not containing two numbers with square sum (like https://oeis.org/A203988 except elements of the form $\frac{(2k)^2}{2}$ in this sequence) and $A'=\mathbb N -A$ . Suppose $A_1,A_2,...$ is an infinite non-empty partition of $A$, now $f$ could be defined as below
$$ f(n) = \begin{cases} a=\frac{(2k)^2}{2}& \quad \text{if } n \in A' \\a_1^2-a & \quad \text{if } n \in A_1\\a_2^2-a & \quad \text{if } n \in A_2\\.\\.\\. \end{cases} $$ where $k$ and $a_i \in \mathbb N$ .
Now if $x,y \in \mathbb N$ and $x+y$ is a perfect square, then both of $x$ and $y$ should be contained in $A'$, or on of them is in $A'$ and another one is in $A$ (and so contained in one of the $A_i$), in both cases $f(x)+f(y)$ is a perfect square .