[proofplan]
We prove both implications directly from the categorical definition of a monomorphism. If $f$ is injective, then equality after composing with $f$ forces pointwise equality of any two maps into $X$. Conversely, if $f$ is monic, we test the monomorphism condition against maps from a singleton set to show that two elements of $X$ with the same image under $f$ must be equal.
[/proofplan]
[step:Use injectivity to prove left cancellation against arbitrary maps]
Assume that $f: X \to Y$ is injective. To prove that $f$ is a monomorphism in $\mathbf{Set}$, let $Z$ be a set and let
\begin{align*}
g: Z &\to X, \\
h: Z &\to X
\end{align*}
be functions such that $f \circ g = f \circ h$ as functions $Z \to Y$.
For each $z \in Z$, equality of the two composite functions gives
\begin{align*}
f(g(z)) = (f \circ g)(z) = (f \circ h)(z) = f(h(z)).
\end{align*}
Since $f$ is injective, this implies $g(z) = h(z)$. Therefore $g$ and $h$ agree at every element of $Z$, so $g = h$ as functions $Z \to X$. Hence $f$ is left-cancellative with respect to all maps into $X$, and so $f$ is a monomorphism in $\mathbf{Set}$.
[/step]
[step:Test monicity on a singleton to prove injectivity]
Assume that $f: X \to Y$ is a monomorphism in $\mathbf{Set}$. Let $x_0, x_1 \in X$ satisfy
\begin{align*}
f(x_0) = f(x_1).
\end{align*}
We prove $x_0 = x_1$.
Let $1 := \{*\}$ be the singleton set. Define functions
\begin{align*}
g: 1 &\to X, & * &\mapsto x_0, \\
h: 1 &\to X, & * &\mapsto x_1.
\end{align*}
Then the composites $f \circ g: 1 \to Y$ and $f \circ h: 1 \to Y$ satisfy
\begin{align*}
(f \circ g)(*) = f(x_0) = f(x_1) = (f \circ h)(*).
\end{align*}
Since $1$ has exactly one element, this proves $f \circ g = f \circ h$ as functions $1 \to Y$.
Because $f$ is a monomorphism, the equality $f \circ g = f \circ h$ implies $g = h$. Evaluating both sides at $*$ gives
\begin{align*}
x_0 = g(*) = h(*) = x_1.
\end{align*}
Thus any two elements of $X$ with the same image under $f$ are equal, so $f$ is injective.
[/step]
[step:Combine the two implications]
The first step proves that every injective function $f: X \to Y$ is a monomorphism in $\mathbf{Set}$. The second step proves that every monomorphism $f: X \to Y$ in $\mathbf{Set}$ is injective. Therefore $f$ is a monomorphism in $\mathbf{Set}$ if and only if $f$ is injective.
[/step]