So I read this theorem:
Suppose $f$ is a continuous $1-1$ mapping of a compact metric space $X$ onto a metric space $Y$. Then the inverse mapping $f^{-1}$ defined on $Y$ by $$ f^{-1}(f(x))=x \quad x\in X $$ is a continuous mapping of $Y$ onto $X$.
Can someone please explain why compactness of $X$ is necessary here? I mean why is it not possible for $f^{-1}$ to be continuous without $X$ being compact?
Let's just prove it, and will be clear where we'll use compactness. Let $F \subseteq X$ be closed. Let's prove that the inverse image $(f^{-1})^{-1}(F)$ of $F$ by $f^{-1}$ is closed. Since $F$ is closed and $X$ is compact, $F$ is also compact. Since $F$ is continuous, $f(F) = (f^{-1})^{-1}(F)$ is compact in $Y$. Since $Y$ is a metric space, it is Hausdorff, and in these spaces, every compact set is closed. As we wanted.
Essential facts: