[guided]We want to show $f = g$ on all of $X$, knowing they agree on the dense subset $A$. The strategy is to show that the set where $f$ and $g$ agree is closed, and then use density.
Define the coincidence set $E := \{x \in X : f(x) = g(x)\}$. We claim $E$ is closed, or equivalently, $X \setminus E$ is open.
Take any $x \in X \setminus E$. Then $f(x) \neq g(x)$ — these are two distinct points of $Y$. Since $Y$ is Hausdorff, the separation axiom provides disjoint open sets $V_1, V_2 \subset Y$ with $f(x) \in V_1$ and $g(x) \in V_2$, and $V_1 \cap V_2 = \varnothing$.
Now we pull back to $X$. Define $W := f^{-1}(V_1) \cap g^{-1}(V_2)$. Since $f$ is continuous, $f^{-1}(V_1)$ is open in $X$. Since $g$ is continuous, $g^{-1}(V_2)$ is open in $X$. The intersection $W$ of two open sets is open, and $x \in W$ (since $f(x) \in V_1$ and $g(x) \in V_2$).
We verify $W \subset X \setminus E$: for any $z \in W$, we have $f(z) \in V_1$ and $g(z) \in V_2$. Since $V_1$ and $V_2$ are disjoint, $f(z) \neq g(z)$, so $z \notin E$.
We have shown that every point of $X \setminus E$ has an open neighbourhood contained in $X \setminus E$. Hence $X \setminus E$ is open, and $E$ is closed.
This is precisely where the Hausdorff hypothesis on $Y$ is consumed. If $Y$ were not Hausdorff — for example, $Y$ with the indiscrete topology — distinct points $f(x)$ and $g(x)$ could not be separated, and the argument would fail. Indeed, the theorem is false without the Hausdorff condition: take $Y = \{0, 1\}$ with the indiscrete topology, $X = \mathbb{R}$, $A = \mathbb{R} \setminus \{0\}$, $f \equiv 0$, and $g = \mathbb{1}_{\{0\}}$. Then $f|_A = g|_A = 0$ but $f(0) \neq g(0)$.[/guided]