It is clear that if a semigroup is embedded into a group, it must be cancellative.
Clifford, Preston: The Algebraic Theory of Semigroups - Page 34. See also A. Nagy: Special classes of semigroups, Theorem 3.10,
p.46
A commutative semigroup can be embedded in a group if and only if it is cancellative. The usual procedure for doing this by means of ordered pairs, is just like that of embedding an integral domain in a field.
This construction is sometimes called group of
quotients. This article at proofwiki is somewhat related to this construction.
For non-commutative semigroups, the situation is more complicated.
Clifford, Preston: The Algebraic Theory of Semigroups - Page
36
A cancellative semigroup $S$ can be embedded in a group of left quotients of $S$ if
and only if it is right reversible.
This paper might also be of interest: George C. Bush: The embeddability of a semigroup--Conditions common to Mal'cev and Lambek, Trans. Amer. Math. Soc. 157 (1971), 437-448.
EDIT: See also this wikipedia article which contains all the information I've given above and also a few further references. (Perhaps I should have searched wikipedia first, before posting this...)
Let me work only with groups for the sake of familiarity.
The wreath product is defined using the semidirect product, so the first step is to understand the semidirect product categorically. I claim that the correct way to understand the semidirect product is not categorically but higher-categorically, and also that the correct higher-categorical perspective makes it clear that the semidirect product is not a product. The basic claim is the following:
Let $\varphi : G \to \text{Aut}(H)$ be an action of a group $G$ on a group $H$. Then the semidirect product $H \rtimes G$ is the homotopy quotient of $H$ by the action of $G$.
In other words, the semidirect product is not a limit or a colimit, but a 2-colimit (in fact it's the simplest interesting example I know of a 2-colimit).
What does this mean? More generally, let a group $G$ act by automorphisms on an object $c$ in an arbitrary category $C$. The ordinary quotient of $c$ by $G$ is the colimit of the corresponding diagram $BG \to C$, where $BG$ is the one-object category corresponding to $G$. Explicitly, it is an object $c_G$ such that there are natural bijections
$$\text{Hom}(c_G, d) \cong \text{Hom}(c, d)^G.$$
More explicitly, morphisms $c_G \to d$ are $G$-invariant morphisms $c \to d$, where $G$ acts on $\text{Hom}(c, d)$ by precomposition (this is a right action). Even more explicitly, in a concrete category this means that morphisms $c_G \to d$ are morphisms $c \to d$ which take the same value on $G$-orbits.
In particular, we can let $C = \text{Grp}$ and this gives us a notion of the quotient of a group by the action of a group. However, this construction is poorly behaved: explicitly, if $\varphi : G \to \text{Aut}(H)$ is such a group action, then the quotient is the quotient of $H$ by the relations $\varphi(g) h = h$ for all $g \in G, h \in H$, and this construction will often destroy a lot of information about the group action.
But it is possible to do something less violent. In the world of homotopy theory, a less violent alternative to identifying two points of a space is putting a path in between them, which identifies them up to homotopy; this idea leads to things like the mapping cone. I claim that we can do the same sort of thing with groups, thanks to the following important observation:
Groups naturally form a 2-category, not just a category.
This is because groups $G$ are secretly themselves categories $BG$ with one object. Functors between these categories give group homomorphisms, but we can talk not only about functors but about natural transformations. It is a very good exercise to prove the following.
Claim: Let $\varphi_1, \varphi_2 : G \to H$ be a pair of morphisms between groups. Then a natural transformation $\varphi_1 \to \varphi_2$ is precisely an element $h \in H$ such that $\varphi_2(-) h = h \varphi_1(-)$, or equivalently such that $\varphi_2(-) = h \varphi_1(-) h^{-1}$.
The topological picture here is to think of $G, H$ as fundamental groups of based spaces $X, Y$, so that $\varphi_1, \varphi_2$ are induced by two based maps $f_1, f_2 : X \to Y$, and we want to understand when $\varphi_1, \varphi_2$ are freely homotopic (so a homotopy which ignores the basepoints). What can happen is that in a homotopy from $\varphi_1$ to $\varphi_2$ the basepoint can travel around a nontrivial loop in $Y$, which is precisely the element $h$ above.
The idea now is that instead of forcing two elements $h_1, h_2$ of a group to become equal in a quotient, we can "put a path between them" by adjoining a new element $g$ such that $h_2 g = g h_1$, or equivalently such that $h_2 = g h_1 g^{-1}$. This is essentially what happens in the construction of the semidirect product, one presentation of which is
$$H \rtimes G = \langle G, H | \varphi(g) h = ghg^{-1} \rangle.$$
Here I mean the quotient of the free product of $G$ and $H$ by the specified relations. I can be more formal here but it may not be all that helpful to do so; in particular the resulting notion of homotopy quotient can also be described by a universal property, but now involving a natural equivalence of categories rather than a natural bijection of sets.
Anyway, let me connect all this back up to spaces and also to wreath products to describe a topological example of this homotopy quotient idea at work. Take a path-connected space $X$ and consider the space $X^n$ of $n$-tuples of elements in $X$. The quotient $X^n/S_n$ is the configuration space of $n$ unordered and not necessarily distinct elements of $X$, but quotients of spaces by group actions can often fail to be well-behaved, and in homotopy theory-land we can instead take the homotopy quotient, explicitly described by the Borel construction
$$(X^n \times ES_n)/S_n.$$
This is a kind of "homotopy configuration space." The punchline is now that the fundamental group of this space is the wreath product $\pi_1(X) \wr S_n$. (This isn't just a random example either; these spaces can be used, among other things, to define the Steenrod operations.)
Best Answer
What you are describing is the left adjoint of the forgetful functor from Group to Semigroup.
In the case of monoids and monoid homomorphisms, such a group is called the enveloping group of a monoid. You can find the description in George Bergman's Invitation to General Algebra and Universal Constructions, Chapter 3, Section 3.11, pages 65 and 66.
However, you don't always get embeddings.
For semigroups, the most natural thing is to adjoin a $1$, even if the semigroup already has one, and then perform the construction. If $S$ already had an identity, the construction will naturally collapse the new, adjoined, identity into the original one, and give you "the most general group into which you can map the semigroup".
Added. In fact, what the last construction is doing (for semigroups) is simply composing the two right adjoints: the right adjoint of the forgetful functor from Monoid to Semigroup is the functor that adjoins an identity (since even between monoids there are generally more semigroup homomorphisms than monoid homomorphisms). So if we look at the composition of the forgetful functors Group $\longrightarrow$ Monoid $\longrightarrow$ Semigroup, we obtain a right adjoint by composing the adjoints going the other way, Semigroup $\longrightarrow$ Monoid (adjoin a $1$), and Monoid $\longrightarrow$ Group (enveloping group). So: first adjoin a $1$, then construct the enveloping group.
(Interestingly, there is another functor from monoids to groups, namely the functor that assigns to every monoid its group of units, $M^*$. This functor is the right adjoint of the forgetful functor: given any monoid $M$ and any group $G$, there is a natural corespondence between $\mathbf{Monoid}(G,M)$ and $\mathbf{Group}(G,M^*)$).