Notation: All variable-symbols for numbers, except $A$ and $B$, which occur near the end, are positive integers.
By induction. We have $2=1^2+1^2.$ The inductive hypothesis is that prime $p\equiv 1\mod 4$ and that every prime $q<p$ such that $q\not\equiv 3\mod 4$ is a sum of two squares. We show this implies $p$ is a sum of two squares.
Let $S =\{n:\exists x,y\;(x^2+y^2=np\}.$ Let $N=\min S.$ Of course we want to show that $N=1$. Let $a^2+b^2=Np .$
(1). We know $N<p$ because there exists $x$ with $x\leq (p-1)/2$ such that $(x^2+1)/p\in S,$ and we have $(x^2+1)/p<((p/2)^2+1)/p<p.$
(2). We have $a<p$ and $b<p$ (otherwise $N=(a^2+b^2)/p\geq p$).
(3). We have $\gcd(a,b)=1.$ Proof: Suppose $a=a_1z$ and $b=b_1z.$ Now $\gcd (z^2,p)=1 $ (because $z\leq a<p,$ and $p$ is prime) and $z^2|(Np),$ so $z^2|N.$ Therefore $$(a_1^2+b_1^2)/p= (a^2+b^2)/(z^2p)=(Np)/ (z^2p)=N/z^2\in \Bbb N .$$ $\quad$ So $\min S=N\geq N/z^2\in S,$ so $z=1.$
(4). We need the result that if $q$ is prime and $q\equiv 3\mod 4$ then $q\not|\;(x^2+y^2)$ unless $q|x$ and $q|y.$ Any prime divisor of $N$ is a divisor of $a^2+b^2,$ and $\gcd(a,b)=1.$ Therefore no prime divisor of $N $ is $\equiv 3$ modulo $4.$
(5). Finally we show by contradiction that $N=1.$ Suppose instead that a prime $q$ divides $N.$ The inductive hypothesis and (4) and (1) imply that $q=u^2+v^2$ for some $u,v.$ Let $v\equiv ju \mod q$ where $j^2+1\equiv 0\mod q.$ Since $q|(a^2+b^2)$ and $\gcd(a,b)=1$ we have $b\equiv \pm ja\mod q .$
Let $N=N'q.$ We have $$N'q^2p=Nqp=q(a^2+b^2)=$$ $$ =(u^2+v^2)(a^2+b^2)=$$
$$ (i)...\quad =(ua+vb)^2+(ub-va)^2=$$ $$(ii)....\quad
=(ua-vb)^2+(ub+va)^2.$$ Since $v\equiv ju \mod q$ and $b\equiv \pm ja\mod q,$ one of expressions in (i),(ii) above is equal to $(qA)^2+(qB)^2$ for some non-negative integers $A,B$.
So $N'q^2p=(Aq)^2+(Bq)^2.$ So $N'p=A^2+B^2.$ Now $0<N'<p$ and $p$ is prime so $N'p$ is not a square, so $A\ne 0\ne B.$ So $N'\in S.$ But $\min S=N>N'\in S,$ a contradiction.
We conclude that $N=1$, so $a^2+b^2=Np=p.$