Why is this the coequalizer in $\mathbf {Set}$?
To show that $g$ is well-defined, notice that $\{(y,z)\in Y\times Y:f(y)=f(z)\}$ is an equivalence relation on $Y$ that includes your $R$ as a subset. So it includes the equivalence relation $\sim$ generated by $R$ (by definition of "generated"). That is, if $y\sim z$ then $f(y)=f(z)$, which is exactly what you need to make $g$ well-defined.
You're spot on with the intuition here. To prove that $g$ is well defined, note that since $fs = ft$, then for any $y \sim y'$ in $Y$ we have $f(y) = f(y')$. This is a consequence of how we have defined the relation on $Y$ (it holds for the generators, which are pairs $s(x) \sim t(x)$, because $f(s(x)) = f(t(x))$. You should prove that therefore it holds for any equivalent pair of elements).
By the remark in the OP, this says that $f$ induces a map $g$ defined as $g([y]) = f(y)$, which is precisely to say that $g\pi = f$. Note that we get uniqueness for free: if we were to have another map $h$ such that $h\pi = f$ then we should have
$$ g\pi = f= h\pi, $$
and since $\pi$ is epi this says that $g = h$.