I did this differently than Thorgott, but that seems like a nice solution. Honestly, I have never proven that open/closed immersions are monomorphisms so I'd be interested in seeing the details.
Anyway, here is how I did this problem when in came up in Vakil's notes.
First, let's understand how close $\Delta: X \to X \times_Y X$ is to being a closed immersion. For each $x \in X$, and affine neighborhood $V$ of $f(x)$, we can find an affine neighborhood $U \subset f^{-1}(V)$ of $x$, so that $\Delta|_U: U \to U\times_V U$ is a closed immersion. We also notice that by construction, $U = \Delta^{-1}(U \times_V U). $ (let me know if this isn't clear.) As such, $\Delta$ can be viewed as a morphism $g: S \to T$ satisfying the following property:
For every $s \in S$, there is a neighborhood $V_s$ of $g(s)$ so that $g|_{g^{-1}(V)}: g^{-1}(V) \to V$ is a closed immersion.
Now, let $V = \bigcup_{s \in S} V_s \subset T$. Then, $g(S) \subset V$, so $g$ factors $$S \stackrel{g'}\to V \hookrightarrow T$$
and $V \hookrightarrow T$ is an open immersion. As such, we just need to show that $g'$ is a closed immersion. But now, this just follows from the local nature of closed immersions, which can be found here and here.