Simplification: Let $m=p_1^{\alpha_1}\cdots p_t^{\alpha_t}$ where the $p_i$ are distinct primes. Then the congruence $x^2\equiv a \pmod{m}$ has a solution if and only if each of the congruences $x^2\equiv a \pmod{p_i^{\alpha_i}}$ has a solution.
One direction is obvious. A solution modulo $m$ is also a solution modulo $p_i^{\alpha_i}$.
For the other direction, for each $i$ let $x_i$ be such that $x_i^2\equiv a\pmod{p_i^{\alpha_i}}$. By the Chinese Remainder Theorem, there is an $x$ such that $x\equiv x_i \pmod{p_i^{\alpha_i}}$ for all $i$ from $1$ to $t$. This $x$ is a solution of the congruence $x^2\equiv a\pmod{m}$.
Working with prime powers: So now it is sufficient to prove the result for $m=p^{\alpha}$, where $p$ is prime. Let $p^\beta$ be the largest power of $p$ that divides $a$.
We need to show that the congruence has a solution if and only if one of the two conditions of the post holds.
The case $\beta\ge \alpha$ is easy, for $x=0$ is a solution.
Suppose now that $\beta\lt \alpha$. Suppose that $x^2\equiv a \pmod{p^\alpha}$. and let $p^\gamma$ be the highest power of $p$ that divides $x$. Then unless $\gamma=\beta/2$, $x^2-a$ cannot be divisible by $p^\alpha$.
So $\beta=2\gamma$ must be even.
Let $x=p^{\beta/2}y$. Then $p^{\beta}y^2\equiv a\pmod{p^{\alpha}}$. Dividing through by $p^{\beta}$ we get
$$y^2\equiv a/p^{\beta}\pmod{p^{\alpha-\beta}}.$$
In particular, since $\beta-\alpha\ge 1$, we have
$$y^2\equiv a/p^{\beta}\pmod{p},$$
and therefore $a/p^{\beta}$ is a quadratic residue of $p$.
We leave showing that $a/p^{\beta}$ being a quadratic residue of $p$ is sufficient in the case $\beta\lt \alpha$. One needs to show that a solution of the congruence $y^2\equiv a/p^{\beta}\pmod{p}$ can be lifted to a solution modulo any power of $p$, in particular $p^{\alpha-\beta}$.