The universal property implies that the map must be a one-to-one set-theoretic map.
To see this, let $a,b\in S$ be such that $g(a)=g(b)$. Let $G$ be a nontrivial group (e.g., $G=C_2$, the cyclic group of order $2$) and let $g\in G$ be a nontrivial element. Let $f\colon S\to G$ be defined by
$$f(s) = \left\{\begin{array}{ll}
1 & \text{if }s\neq a,\\
g &\text{if }s=a.
\end{array}\right.$$
By the universal property, there exists a group homomorphism $\varphi\colon F\to G$ such that $f=\varphi\circ g$. In particular, $f(b) = \varphi(g(b)) = \varphi(g(a)) = f(a) = g$, hence $b=a$ (since the only element of $S$ that is mapped to $g$ by $f$ is $a$).
Therefore, $g$ is one-to-one.
Once you know it is one-to-one, you may replace $S$ with $g(S)$ and consider it to be the inclusion, since the universal property also gives:
Theorem. Let $S$ and $T$ be sets, and let $f\colon S\to T$ be a bijection. If $(g,F_S)$ and $(h,F_T)$ are free groups on $S$ and on $T$, then $f$ induces a unique isomorphism $\Phi\colon F_S\to F_T$ such that $\Phi\circ g = h$ and $\Phi(g(s)) = h(f(s))$ for all $s\in S$.
Proof. Use the universal property of $(g,F_S)$ with $h\circ f$ to obtain $\Phi$. Then use the universal property of $(h,F_T)$ with $g\circ f^{-1}$ to obtain a map $\Psi$. Finally, use the uniqueness clause of the definition to prove that $\Phi\circ\Psi$ and $\Psi\circ\Phi$ are the corresponding identity morphisms. $\Box$
So we can replace a free group on $S$ $(g,F_S)$ with the free group $(\iota,F_{g(S)})$ which is free on $g(S)$, and which is canonically isomorphic to $(g,F_S)$.
You're working too hard. I'll assume you're convinced that $\mathbb{Z}$ is the free group on one generator, which means you're convinced that
$$\text{Hom}(\mathbb{Z}, G) \cong G$$
(where the RHS should really be the underlying set of $G$ but I'm omitting that I'm applying the underlying set functor). One way to state the universal property of the coproduct is that
$$\text{Hom}(X \sqcup Y, Z) \cong \text{Hom}(X, Z) \times \text{Hom}(Y, Z)$$
from which it follows that
$$\text{Hom}(\mathbb{Z} \sqcup \mathbb{Z}, G) \cong G \times G$$
and this is also the universal property of the free group on two generators, so you're done by the Yoneda lemma. The argument is exactly the same for the free group on $n$ generators, and in fact on a set's worth of generators.
More abstractly, the forgetful functor $\text{Grp} \to \text{Set}$ has a left adjoint, the free group functor. As a left adjoint, it preserves colimits, and in particular coproducts. But every set $X$ is the coproduct of $X$ copies of the $1$-element set, so it follows that the free group $F_X$ is the coproduct of $X$ copies of $\mathbb{Z}$.
Best Answer
As you say, $S$ is a set, so this is a diagram in $\text{Set}$. The fact that we force $\varphi$ to be a homomorphism of groups is extra structure that isn't captured by the diagram alone.
You might consider this unsatisfying, so alternatively we can explicitly name the forgetful functor $U : \text{Grp} \to \text{Set}$ from groups to sets, which is being implicitly applied to $G$ here, and regard $f$ as a morphism $f : S \to U(G)$ in $\text{Set}$, then talk about the universal property in terms of the adjunction
$$\text{Hom}_{\text{Grp}}(F(S), G) \cong \text{Hom}_{\text{Set}}(S, U(G)).$$