Hint $\ $ Suppose for induction there is a solution $\,x = a\,$ to the first $\,n\!-\!1\,$ congruences, i.e.
$$a\equiv a_i\!\!\pmod{m_i},\,\ i=1,\ldots n-1\tag{#}$$
Combining the solution with the final congruence we obtain the system
$$\begin{align} &x \equiv a\! \pmod m,\ \ m = {\rm lcm}(m_1,\ldots m_{n-1})\\
&x\equiv a_n\!\!\!\! \pmod{m_n}\end{align}$$
We know this is solvable iff $\,(m_n,m)\mid a-a_n.\ $ Since gcd distributes over lcm we have
$$(m_n,m) = (m_n,{\rm lcm}(m_1,\ldots m_{n-1}) = {\rm lcm}((m_n,m_1),\ldots,(m_n,m_{n-1})) =: \ell $$
Hence $\ (m_n,m)\mid a-a_n \iff \ell\mid a-a_n\iff (m_n,m_i)\mid a-a_n,\ $ for all $\,i \le n-1$
$\ \ (m_n,m_i)\mid m_i\mid a-a_i\,$ since $\,a\,$ is a solution of the first $\,n-1\,$ congruences $\,({\#})$
$\qquad\ \ (m_n,m_i)\mid a_n\!-\!a_i\,$ by hypothesis. Therefore it divides their difference, i.e.
$\qquad\ \ (m_n,m_i)\mid a-a_n = a-a_i -(a_n - a_i).\ $ Therefore a solution exists.
Remark $ $ Domains that satisfy an analogous Chinese Remainder Theorem (CRT) solvability criterion are known as Prüfer domains. They are non-Noetherian generalizations of PIDs and Dedekind domains. Their ubiquity stems from a remarkable confluence of interesting characterizations, e.g. or Gauss's Lemma for polynomial content ideals, or for ideals: $\rm\ A\cap (B + C) = A\cap B + A\cap C\,,\ $ or the $\rm\, GCD\cdot LCM\,$ law: $\rm\, (A + B)\ (A \cap B) = AB\,,\ $ or $\,$ "contains $\rm\Rightarrow$ divides" $\rm\ A\supset B\ \Rightarrow\ A\,|\,B\ $ for finitely generated $\rm\,A.\,$ See this answer for a couple dozen characterizatons (likely over $100$ are known).