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)$.
Let $A = {a_1,a_2}$ and $G = \langle A\rangle$ a free group of rank $2$.
(1)
By the theorem, a homomorphism $\varphi : G \to \mathbb Z_4$ is uniquely determined by $\varphi(a_1)$ and $\varphi(a_2)$.
Moreover, since $G$ is free on $A$, any combination of $\varphi(a_1)$ and $\varphi(a_2)$ gives rise to a homomorphism.
Since there are $4$ choices for $\varphi(a_1) \in \mathbb Z_4$ and independently $4$ choices for $\varphi(a_2) \in \mathbb Z_4$, the total number of homomorphisms $G \to \mathbb Z_4$ equals $4\cdot 4 = 16$.
(2a)
We have that $\operatorname{im}(\varphi) = \langle \varphi(a_1) ,\varphi(a_2) \rangle$, which is a subgroup of $G$.
The subgroup structure of $\mathbb Z_4$ is
$$\{0\} \subset \{0 , 2\} \subset \mathbb Z_4.$$
So $\operatorname{im}(\varphi) \neq \mathbb Z_4$ if and only if $\operatorname{im}(\varphi) \subseteq \{0 , 2\}$.
By the counting strategy of (1), there are $2\cdot 2 = 4$ such homomorphisms. Thus, the remaining $16 - 4 = 12$ homomorphisms $G \to \mathbb Z_4$ have $\operatorname{im} \varphi = \mathbb Z_4$ (which means they are onto).
(2b)
This is a bit harder than (2a) since the subgroup structure of $G' = \mathbb Z_6$ is a bit more complicated than that of $G' = \mathbb Z_4$.
The proper subgroups of $\mathbb Z_6$ are $H_1 = \{0\}$, $H_2 = \{0,3\}$ and $H_3 = \{0,2,4\}$.
As before, there is $1\cdot 1 = 1$ homomorphism $\varphi$ with $\operatorname{im}\varphi = H_1$. This one is the trivial homomorphism, of course.
There are $2\cdot 2 = 4$ homomorphisms $\varphi$ with $\operatorname{im}\varphi \subseteq H_2$.
Among those homomorphisms, there is the trivial homomorphism with image $H_1$. Since the only further subgroup of $H_2$ is $H_2$, we get that the other $4 - 1 = 3$ homomorphisms have image $H_2$.
Similarly, there are $3^2 - 1 = 8$ homomorphisms with image $H_3$.
Therefore, the number of homomorphisms with image $\mathbb Z_6$ (these are exactly the onto ones) is $6^2 - 1 - 3 - 8 = 24$.
Best Answer
As $\text{Hom}(F(S),G)$ is in natural correspondence with $\text{Map}(S,G)$, they are equinumerous: there are $|G|^{|S|}$ homomorphisms from $F(S)$ to $G$.