Let $p$ be an odd prime number and $n$ be a positive integer. I want to consider roots of the equation $x^{2}+1=0$ in the ring $\Bbb Z/p^{n}\Bbb Z$.
Suppose $n=1$. Find a condition on $p$ such that $x=r \mod p$ ($r$ is an integer) is a root of $x^{2}+1=0$.
By this question&answer, I found that $p\equiv 1 \bmod 4$ and $r$ is either $ab^{-1}$ or $a^{-1}b$ in $\Bbb Z/p\Bbb Z$ where $p=a^2+b^2$.
Assume that $p\equiv 1 \bmod 4$. I want to prove $x=r^{p^{n-1}} \mod p^{n}$ is a root of $x^{2}+1=0$ in $\Bbb Z/p^{n}\Bbb Z$.
As above, we have already determined $r$ but over module $p$. I donot know how can we deal with module $p^n$. Maybe a property like $x^p \equiv y^p \bmod p^2$ if $x \equiv y \bmod p$ will work?
My goal is to define the number of roots of $x^{2}+1=0$ in $\Bbb Z/p^{n}\Bbb Z$.
It should be depended on $p$ and $r$. But I could not make it clear.
Any help would be much appreciated.
Let $p$ be a prime congruent to $1$ modulo $4$, and suppose that $r_1^2\equiv -1\pmod{p}$. Let $r_n=r_1^{p^{n-1}}$. We show by induction on $n$ that $r_n^2\equiv -1\pmod{p^n}$.
For the induction step, suppose that for the positive integer $k$ we have $r_k^2\equiv -1\pmod{p^k}$. We will show that $r_{k+1}^2\equiv -1\pmod{p^{k+1}}$.
By the induction assumption, we have $r_k^2=-1+sp^k$ for some integer $s$. Since $r_{k+1}=r_k^p$, we have $$r_{k+1}^2=(r_k^2)^p=(-1+sp^k)^p.$$ Expand $(-1+sp^k)^p$ using the Binomial Theorem. We get $$(-1+sp^k)^p=-1+p(sp^k)-\binom{p}{2}(sp^k)^2+\cdots.\tag{1}$$ Every term on the right-hand side of (1) after $-1$ is divisible by $p^{k+1}$. This completes the proof that $r_{k+1}^2\equiv -1\pmod{p^{k+1}}$.
Remark: The above answers the question as you put it, but is probably not a full answer to the question you were originally asked. If one is to give a full answer, the exact question should be given.
For a prime $p$ of the form $4k+1$, the congruence $x^2+1\equiv 0\pmod{p^n}$ has exactly two solutions, one the "negative" of the other. Your characterization of the solutions of $x^2+1\equiv 0\pmod{p}$ in terms of the representation of $p$ as a sum of two squares is correct, but there are other characterizations. And there are other approaches to the solutions modulo $p^n$, such as Hensel lifting.