Injective vs. monic (in categories where it makes sense)
Solution 1:
A category $\mathscr{C}$ is concrete if there is a faithful functor $\mathbf{U}\colon\mathscr{C}\to\mathscr{S}et$. You can think of this as telling you that the objects of $\mathscr{C}$ “are” sets and the arrows of $\mathscr{C}$ are set-theoretic functions on those sets. We think of $\mathbf{U}$ as the “underlying set” forgetful functor.
If $\mathscr{C}$ is concrete, and $f$ is a morphism that is injective on underlying sets, then $f$ is monic in $\mathscr{C}$. This follows because the faithfulness of the underlying set functor: if $fg = fh$, then $\mathbf{U}(f)\mathbf{U}(g) = \mathbf{U}(f)\mathbf{U}(h)$, and since $\mathbf{U}(f)$ is assumed to be injective it follows that $\mathbf{U}(g)=\mathbf{U}(h)$; the faithfulness of $\mathbf{U}$ now tells you that $g=h$, proving that $f$ is left cancellable, i.e. monic in $\mathscr{C}$.
However, it is not true that in concrete categories all monics have underlying injective function, as noted by Jim. It is not easy to come up with examples, because if a category has a free object on one element, then all monics are injective. And in most categories of algebras (in the sense of universal algebra: sets with operations) you have free objects in one element.
(A free object in one element is an object $F$ together with a distinguished element $a\in \mathbf{U}(F)$ such that for every object $X$ and every element $x\in \mathbf{U}(X)$ there is a unique morphism $f\colon F\to X$ such that $U(f)(a)=x$).
I’m not sure what you mean by $A=\langle a,b\rangle$. Perhaps you mean the free group in two elements? If so, your proof is essentially the same as using the free group in one element. But if it means some other group, then you need to justify that your $f$ is actually a group morphism. In general, you can’t define group morphisms by mapping generators to arbitrary elements... unless you are dealing with a free group and a free basis for that free group.
In general, if $\mathscr{C}$ is concrete, then if the underlying set functor has a left adjoint, then all monics are injective, and in general limits (in the categorical sense) are respected by $\mathbf{U}$; that’s why the underlying set of a product of groups is the product of the underlying sets of a group, the underlying set of an inverse limit is the inverse limit of the underlying sets, etc. And the same is true for abelian groups, rings, vector spaces, and topological spaces. If the underlying set functor has a right adjoint, then all epis are surjective, and more generally all colimits are respected by $\mathbf{U}$: so the underlying set of a coproduct is the disjoint union of the underlying set (the disjoint union being the coproduct in the category of sets); the underlying set of a coequalizer is the coequalizer of the underlying functions; the underlying set of a direct limit is the direct limit of the underlying sets; etc.
In most (but not all) categories of algebras, monics are injective because you usually (but not always) have free objects on one element (the free object construction is the left adjoint of the underlying set functor). In very few categories of algebras does the underlying set functor have a right adjoint; nonetheless, in some familiar categories epis are surjective anyway (category of all groups, of all abelian groups, of vector spaces). But in some familiar categories, they are not: in semigroups, the embedding $\mathbb{N}\hookrightarrow\mathbb{Z}$, and in rings, the embedding $\mathbb{Z}\hookrightarrow\mathbb{Q}$, are nonsurjective epimorphisms. Even in some nice categories of groups (some varieties) you may have nonsurjective epimorphisms.
Solution 2:
1) It is true that injections are always monic when we're talking about categories whose objects are sets with additional structure. To be precise, this is true whenever equality of the underlying set maps implies equality of the morphisms in your category. Put another way, the functor from your category to the category of sets that just forgets the additional structure must be a faithful functor for the proof to work. Having a faithful functor into the category of sets is precisely the definition of a concrete category.
2) The free group on a $1$ element set is the group $\mathbb Z$, not a cyclic group. And yes, the proof you've listed using the free group on two elements is correct (assuming $b$ maps to the same "anything" in both those maps), there's nothing technically wrong with it, it's just not optimally simple. The $b$ in your proof is basically irrelevant. All you really need is the $a$ part of the free group, so your really just doing the usual proof with a free group on one element and adding in an additional complication of having to say where $b$ maps to.
3) When you have a category of sets with additional structure in which some monics fail to be injective it must be the case that free objects can't be constructed in general. I don't know for sure, but I doubt that we can prove the other direction, that failure to construct free objects implies that some monic is not injective, so I hesitate to call this the reason why this fact is true.
As for your question about topological spaces, Geoffrey Trang has answered in the comments.