A proof that continuity of $f:X\to Y$ is equivalent to $\overline{f^{-1}(M)}\subset f^{-1}(\overline{M})$.
If $f$ is continuous, then $f^{-1}(\overline{M})$ is closed. Since $f^{-1}(M) \subset f^{-1}(\overline{M})$, it follows that $\overline{f^{-1}(M)} \subset f^{-1}(\overline{M})$.
For the converse, note that $\overline{f^{-1}(M)} \subset f^{-1}(\overline{M})$ implies that $$f^{-1}(\overline{M})^c=f^{-1}(\overline{M}^c)\subset \overline{f^{-1}(M)}^c=\operatorname{int}(f^{-1}(M)^c)=\operatorname{int}(f^{-1}(M^c)),$$ where we use that the complement of the closure is the interior of the complement. Any open set $U$ can be written as $M^c=\overline{M}^c$ for some closed set $M$, so this implies for $U$ open:
$$f^{-1}(U) \subset \operatorname{int}(f^{-1}(U)).$$
Assume that $f$ is continuous. We will argue by contradiction. Suppose $f(x)\notin \overline{M}.$ Then there exists an open set $V$ in $Y$ such that $f(x)\in V$ and $V\cap M=\emptyset.$ Since $f$ is continuous we have that $f^{-1}(V)$ is open. Moreover, $x\in f^{-1}(V)$ and $f^{-1}(V)\cap f^{-1}(M)=\emptyset.$ So, $x\notin \overline{f^{-1}(M)}.$
Conversely, assume that for any set $M\subset Y$ it is $x\in \overline{f^{-1}(M)}\Rightarrow f(x)\in \overline{M}.$ To show continuity it is enough to show that $\overline{f^{-1}(M)}$ is closed if $M$ is closed. So, assume $M$ is closed, that is, $M=\overline{M}.$ If $\overline{f^{-1}(M)}$ is not closed, then there exists $x\in \overline{f^{-1}(M)}$ such that $x\notin f^{-1}(M).$ But this is impossible since $f(x)\in \overline{M}=M.$