Solution (source code)

= Solution

The <closure> $\overline Z$ is the intersection of all closed subsets containing $Z$; equivalently, every neighbourhood of a point of $\overline Z$ meets $Z$. The subspace is <dense subset>[dense] when $\overline Z=X$. A space is <Hausdorff space>[Hausdorff] when distinct points have disjoint neighbourhoods.

For Hausdorff $Y$, the diagonal $\Delta_Y$ is closed in $Y\times Y$. Thus
$$
E=\{x:f(x)=g(x)\}=(f,g)^{-1}(\Delta_Y)
$$
is closed. Since it contains the dense set $Z$, it equals $X$.

The conclusion fails without Hausdorffness. Let $X=Y=\{0,1\}$ have the <Sierpiński space> topology $\{\varnothing,\{1\},X\}$ and let $Z=\{1\}$, which is dense. The identity map and the constant map with value $1$ are continuous and agree on $Z$, but differ at $0$.