The factorization always exists, but in general is not unique.

Let me identify $A$ with $H$. Clearly, $K$ can be identified with $\ker(f)$. Let $f(A)$ be the image of $A$ in $B$. Then $A$ is an abelian extension of $f(A)$ by $K$. If I understand correctly, you are asking whether given an inclusion $f(A)\hookrightarrow B$, it is possible to find an extension of $B$ by $K$, extending the given extension of $f(A)$. Equivalently, you are asking if it is possible to construct a diagram of the following form, where the rows are short exact, and all the vertical homomorphisms are monomorphisms:
$$\require{AMScd}
\begin{CD}
K @>>> A @>f>> f(A)\\
@V=VV @VVV @VVV \\
K @>>> G @>>> B
\end{CD}
$$
The set of isomorphism classes of abelian extension of $B$ by $K$ is in bijective correspondence with $\operatorname{Ext}(B, K)$, where Ext is taken in the category of abelian groups. The inclusion of groups $f(A)\hookrightarrow B$ induces a **surjective** homomorphism $$\operatorname{Ext}(B, K)\twoheadrightarrow \operatorname{Ext}(f(A), K).$$ Because of the surjectivity, a group extension of $f(A)$ can always be extended to a group extension of $B$.

The reason that the homomorphism is surjective is that the cokernel would be a subgroup of $\operatorname{Ext}^2(B/f(A), K)$, but the category of abelian groups has projective dimension one, so Ext$^2$ is always zero.

On the other hand, the homomorphism of ext groups is not always injective. The kernel is a quotient of $\operatorname{Ext}(B/f(A), K)$. So the lift is not unique.

You can construct an extension of $B$ explicitly as follows. It is a standard result of homological algebra that you can construct a map of free resolutions of the inclusion $f(A)\hookrightarrow B$.
$$\require{AMScd}
\begin{CD}
0@>>> R_A @>>> F_A @>>> f(A)\\
@. @VVV @VVV @VVV \\
0 @>>> R_B @>>> F_B @>>> B
\end{CD}
$$
Such that the homomorphisms $R_A\to R_B$ and $F_A\to F_B$ are split injections. An extension of $f(A)$ by $K$ induces a homomorphism $R_A\to K$. Use the splitting to get a homomorphism $R_B\to K$. Now you have a surjective homomorphism $F_B \oplus_{R_B} K \twoheadrightarrow B$, whose kernel is $K$. This is the desired extension. In your notation, $G=F_B \oplus_{R_B} K$.