I've seen the following definition of a free object in category theory.
Let $\mathcal C$ be a concrete category. Denote by $U\colon\mathcal C\to\mathrm{Set}$ the forgetful functor. Let $X$ be a set. Then an object $F(X)\in\mathcal C$ equipped with an arrow $f_X\colon X\to U(F(X))$ is called the free object of $\mathcal C$ on $X$ if: for all $A\in\mathcal C$ and any function $g\colon X\to U(A)$ in the category of sets, there exists a unique "extension" $g'\colon F(X)\to A$ in the category $\mathcal C$ such that $U(g')\circ f_X=g$.
I looked at some concrete examples of free objects in the category of groups and the category of modules. In each case, the arrow $f_X$ was injective. Does this follow from the definition? Why isn't it included in the definition?
No, it does not follow from the definition. Indeed, it does not even follow from the definition in the case of modules in general. Suppose $R$ is the zero ring (the ring with one element). Then every module over $R$ has one element, and this single module is free on every possible set via every possible map.
If you assume there exists an object $A$ of $\mathcal{C}$ such that $U(A)$ has more than one element, then it does follow that $f_X$ must be injective for any free object. Indeed, suppose $F$ is a free object on $X$ via a map $f_X:X\to U(F)$ and $f_X(x)=f_X(y)$ for some distinct $x,y\in X$. Since $U(A)$ has more than one element, there is a function $g:X\to U(A)$ such that $g(x)\neq g(y)$. Taking the unique $g':F\to A$ such that $U(g')\circ f_X=g$, we get a contradiction, since $U(g')(f(x))=U(g')(f(y))$.