We give an answer to a generalization of the problem, but without proof. The easiest proof uses facts about the factorization of Gaussian integers.
Note that if $n$ is divisible by $4$ or by a prime of the form $4k+3$, then $n$ has no representation as a sum of relatively prime squares. So we can assume that $n$ is of the form $n=p_1^{a_1}p_2^{a_2}\cdots p_s^{a_s}$ or $n=2p_1^{a_1}p_2^{a_2}\cdots p_s^{a_s}$. where the $p_i$ are distinct primes all of the form $4k+1$.
Let $n\gt 2$. Then the number of essentially distinct representations of $n$ as a sum of two relatively prime squares is $2^{s-1}$. In particular, $n$ has exactly $2$ essentially distinct representations as a sum of two relatively prime squares if and only if $s=2$.
The sum of two squares theorem can be proved by working in $\Bbb Z[i]$.
By working in $\Bbb Z[\zeta_3]$ instead, where $\zeta_3$ is a third root of unity, one may prove that an integer greater than one can be written in the form $a^2+3b^2$ if and only if its prime decomposition contains no factor $p^k$ where $k$ is odd and $p$ is a prime $p \equiv 2 \pmod{3}$.
There is a similar statement for every quadratic number field with class number one. This may be proved by using unique factorization in the ring of integers, quadratic reciprocity and the characterization of splitting of primes in quadratic extensions in terms of Legendre symbols.
Here are some more examples:
By working in $\Bbb Z[\sqrt{2}]$, one gets that an integer greater than one can be written in the form $a^2-2b^2$ if and only if its prime decomposition contains no factor $p^k$ where $k$ is odd and $p$ is a prime $p \equiv 3,5 \pmod{8}$.
By working in $\Bbb Z[\sqrt{-2}]$, one gets that an integer greater than one can be written in the form $a^2+2b^2$ if and only if its prime decomposition contains no factor $p^k$ where $k$ is odd and $p$ is a prime $p \equiv 5,7 \pmod{8}$.
Best Answer
In the theorem $a,b$ have to be integers and don't have to be nonzero. So in your example: $4=2^2+0^2$.
So the theorem doesn't really help in your case. $n^2=n^2+0^2$ but that doesn't help you much, since I assume that you have additional assumptions on $a,b$, like for example that they should both be nonzero.