I have been trying to learn more about category theory, and I came across the following exercise that I don't quite understand.
Consider abelian groups $A_i$, for some set of consecutive integers $i$, and along with homomorphisms $f_i:A_i \rightarrow A_{i+1}$.
Show that $A\rightarrow B$ is injective if and only if there is an exact sequence $$ 0 \rightarrow A \rightarrow B \rightarrow C \rightarrow 0 $$ that includes this map. Does this result hold if we instead consider commutative rings with identity? What if we instead consider groups that are not abelian? What if we consider pointed sets (i.e. sets together with a distinguished element "$0$"), with maps that are required to take "$0$" to "$0$"?
The reverse direction is immediate from the definition of an exact sequence in every case. To prove the forward direction for abelian groups, I considered the following:
$$ 0 \xrightarrow{f_1} A \xrightarrow{f_2} B \xrightarrow{f_3}C \xrightarrow{f_4} 0 $$
where I let $C = B / \operatorname{im}(f_2)$, $f_1$ be the zero homomorphism, $f_2$ be the defined injection, $f_3$ be defined by $g \mapsto g\operatorname{im}(f_2)$, and $f_4$ is the zero homomorphism. It is easy to check that this is then an exact sequence. So, the abelian group case holds. However, this construction relies on the fact that since these are abelian groups, $\operatorname{im}(f_2) \triangleleft B$, and thus $B/\operatorname{im}(f_2)$ is a well-defined abelian group.
It is not clear how these results transfer over to the other cases, so I'm not sure how to prove or disprove the other cases. Maybe there is a more general way to prove this result?
In general, and as Stahl mentions in the comments, to properly define exactness we need pretty well-behaved categories, i.e. our objects of interest (abelian groups, modules, rings, etc.) and their morphisms (group/module/ring homomorphisms etc.) have to satisfy certain properties. For Homological Algebra, where exact sequence most prominently show up and are studied, we usually start with abelian categories. The most important, in some sense most basic, example of such categories are module categories over rings (this includes abelian groups as $\mathbb Z$-modules).
Why do I bring this up? Well, a particular property of abelian categories is that we always can take quotient or, more precisely, construct an object which very much behaves like a quotient. This is in the end exactly what allows you to complete any exact sequence $0\to A\to B$ to a short exact sequence (one can show that in any abelian category injectivity, or rather being a monomorphism, is equivalent to $0\to A\to B$ being exact). The relevant axiom of abelian categories making this possible is the existence of cokernels and their behavior.
However, this is generally speaking not possible in non-abelian categories, like the category of groups, the category of (unital commutative) rings or the category of pointed sets. Although there might be analogous statements to $0\to A\to B$ being exact iff $A\to B$ is monic, they do not admit general quotient constructions. Indeed, you cannot quotient by an arbitrary subgroup or subring; you need normal subgroups or ideals for that to work. The category of pointed sets strikes me as an odd one out as "kernel=image" has to be (slightly) modified before you can talk about exactness at all.
Back to you specific question. The statements certainly holds for abelian groups and you have demonstrated why. I suspect it might hold too for pointed sets using quotient sets but I am not completely sure about this right now. To see that it does not hold for arbitrary groups and rings note the following: if we have a short exact sequence
$$ 0\to A\to B\to C\to 0 $$
then $A$ is always a kernel by exactness. However, kernels correspond precisely to normal subgroups and ideals, resp., so pick you favourite non-normal subgroup or non-ideal subring $A\subseteq B$, resp., and use the canonical injection $A\to B$ to obtain a counterexample.