  Let $n\ge 1, e\ge 1, k\ge 2$ and $c$ be integers. An integer $u$ is called a
unit in the ring $\mathbb{Z}_n$ of residue classes modulo $n$ if $\gcd(u,
n)=1$. A unit $u$ is called an exceptional unit in the ring $\mathbb{Z}_n$ if
$\gcd(1-u,n)=1$. We denote by $\mathcal{N}_{k,c,e}(n)$ the number of solutions
$(x_1,...,x_k)$ of the congruence $x_1^e+...+x_k^e\equiv c \pmod n$ with all
$x_i$ being exceptional units in the ring $\mathbb{Z}_n$. In 2017,
Mollahajiaghaei presented a formula for the number of solutions $(x_1,...,x_k)$
of the congruence $x_1^2+...+x_k^2\equiv c\pmod n$ with all $x_i$ being the
units in the ring $\mathbb{Z}_n$. Meanwhile, Yang and Zhao gave an exact
formula for $\mathcal{N}_{k,c,1}(n)$. In this paper, by using Hensel's lemma,
exponential sums and quadratic Gauss sums, we derive an explicit formula for
the number $\mathcal{N}_{k,c,2}(n)$. Our result extends Mollahajiaghaei's
theorem and that of Yang and Zhao.
