Question: For which number $m$ the following equation has a solution? $$n^2 \equiv -1 \mod m $$
Remark: The code below provides the first such numbers: $1,2,5,10,13,17$.
By searching this sequence on OEIS, we find the expected numbers: A008784 (we took its title).
This link contains the following statement:
Numbers whose prime divisors are all congruent to 1 mod 4, with the exception of at most a single factor of 2. - Franklin T. Adams-Watters, Sep 07 2008
Then, the question reduces to prove the above statement.
sage: for m in range(20):
....: for n in range(m):
....: if (n**2+1).mod(m)==0:
....: print([m])
....:
[1]
[2]
[5]
[5]
[10]
[10]
[13]
[13]
[17]
[17]
Worth emphasis is that the result presented in Sebastion's answer is in fact a special case of the following generalized Euler's Criterion.
Theorem $\ $ Let $\ a,\,n\,$ be integers, with $\,a\,$ coprime to $\,n\ =\ 2^e \,p_1^{e_1}\cdots p_k^{e_k}\,,\ \ p_i\,$ primes.
$\qquad\qquad\quad x^2\equiv a \pmod{\!n}\,\ $ is solvable for $\,x\,$
$\quad\ \iff\ \ \, a^{\large (p_i - 1)/2} \equiv 1 \pmod{\!p_i}\quad $ for all $\ i\le k$
$\qquad\qquad\ \ \ $ and $\ \ e>1 \,\Rightarrow\, a\equiv 1\pmod{\! 2^{2+\delta}},\ \ \ \delta = 1\ \ {\rm if}\ \ e\ge 3\ \ {\rm else}\ \ \delta = 0$
Proof: See e.g. Ireland and Rosen, A Classical Introduction to Modern Number Theory, Proposition 5.1.1 p.50.
The above criterion is practical if one knows a full factorization of $\,n,\,$ since the exponentiations may be quickly computed by repeated squaring.
Beware that the criterion cannot be expressed equivalently as a simple Jacobi symbol calculation. For example we have $(8|15) = 1\ $ but $\,8\,$ is not a square $\,\rm (mod\ 15)$.