Riemann'sPointNose has given the answer to your question as written (+1), which is that this is trivially true! Namely, the following statement is trivially true:
Let $(G,\cdot)$ be a group. Then for all $g_1,g_2\in G$ such that $g_1g_2\in G$ we have $g_1,g_2\in G$.
Indeed, you start by assuming that $g_1,g_2$ lie in $G$, and then wish to conclude that $g_1,g_2$ lie in $G$. Do you see why this is a vacuously true statement? The fact that $g_1g_2\in G$ has nothing to do with it, it just follows from the assumption that $g_1,g_2\in G$ to begin with.
However, there's a different way of interpreting your question, which perhaps is more in the spirit of what you were looking for:
For which groups $(G,\cdot)$ is the following true? Whenever $\alpha:G\to G'$ is an injective homomorphism (ie whenever $G$ is "morally" a subgroup of $G'$), we have $ab\in \alpha(G)\implies a,b\in \alpha(G)$ for all $a,b\in G'$.
It turns out that there is no group with this property. In fact, for any homomorphism $\alpha:G\to G'$ of groups, provided that $G'\neq\alpha(G)$ we can always find $a,b\in G'\setminus\alpha(G)$ such that $ab\in\alpha(G)$! Indeed, just pick any $t\in G'\setminus\alpha(G)$, and let $a=t$ and $b=t^{-1}$. So to show that a group $G$ does not have this property we just need to find any group $G'$ with an injective homomorphism $\alpha:G\to G'$ such that $G'\neq\alpha(G)$; for example, we can take $G'=G\times\mathbb{Z}$ and $\alpha(g)=(g,0)$.
I am not sure whether this is a satisfactory answer for you, but thought I'd point it out, as it's in some sense the natural follow-up to the question you asked.