This is basically what quadratic reciprocity is for.
In detail:
By the Chinese Remainder Theorem, $a$ has a square root mod $n$ iff $a$ has a square root mod each $p_i^{\alpha_i}$. So we just need to understand when $a$ is divisible by a prime power $p^{\alpha}$.
If $a$ is divisible by $p^{\alpha}$, then $a$ of course has a square root mod $p^{\alpha}$. Otherwise, let $a = k p^{\beta}$ for $\beta < \alpha$ and $k$ indivisible by $p$. In this case, $a$ has a square root mod $p^{\alpha}$ just in case $\beta$ is even and $a$ has a square root mod $p^{\alpha - \beta}$.
Now we just need to understand when $k$ has a square root modulo a prime power $p^{e}$ such that $k$ is indivisible by $p$.
By Hensel's lifting lemma, for an odd prime $p$ not dividing $k$, we have that $k$ has a square root mod $p^{e}$ iff $k$ has a square root mod $p$ itself.
On the other hand, by a similar but slightly more bothersome argument, for $p = 2$ and odd $k$, we have that $k$ has a square root mod $2^{e}$ iff $k = 1$ mod $2^{\mathrm{min}(3, e)}$. (The argument is slightly more bothersome in this context because we get a repeated root instead of two distinct roots when we take the square root of a nonzero value mod 2)
Now we need to be able to tell when $k$ has a square root modulo an odd prime $p$ not dividing $k$. In jargon, this has to do with the so-called "Legendre symbol". The rules are like so: $k$ is a quadratic residue mod $p$ iff the number of odd-exponent factors in the prime factorization of $k$ which are quadratic non-residues mod $p$ is even. (If $k$ is a negative integer, include also a single factor of -1 correspondingly.)
Finally, we just need to be able to tell when $q$ is a quadratic residue modulo an odd prime $p$, where $q$ is either an odd prime distinct from $p$, or $q$ is $2$, or $q$ is $-1$.
The rules for answering those particular questions are the rules most often called "quadratic reciprocity" (although really, this entire thing might as well have been given that same label).
The most basic quadratic reciprocity rule is that given distinct odd primes $q$ and $p$, we have that $q$ is a quadratic residue mod $p$ iff either ($p$ is a quadratic residue mod $q$ and one or both of $p$ and $q$ are $1$ mod 4) or ($p$ is a quadratic non-residue mod $q$ and both $p$ and $q$ are $-1$ mod 4).
As for the remaining two special cases, $2$ is a quadratic residue mod odd prime $p$ iff $p$ is $\pm 1$ mod $8$, while $-1$ is a quadratic residue mod odd prime $p$ iff $p$ is $1$ mod $4$.
This completes all the rules you need to be able to determine quickly whether $x^2 = a \pmod{n}$ has a solution, given the prime factorization of $n$, the prime factorization and sign of $a$ itself, and the ability to tell which odd primes are quadratic residues mod $a$ itself (which is presumably easy if $a$ itself is small).