Let us begin with the “Riemannian” case. In truth, it doesn’t have much to do with the Riemannian structure at all: $\mathcal{H}$ is the space of all affine maps on $(M,\nabla)$, with the affine connection $\nabla$ given by the Levi-Civita connection.
As you note, this will never have a natural Lie group structure unless $M$ is 0-dimensional, since it will always contain the constant maps. If we make the additional restriction that $f$ be a diffeomorphism, however, we get the group of affine transformations, which has been extensively studied and is well-known to be a Lie group when $M$ has finitely many connected components. For compact Riemannian manifolds, the identity component of the group of affine transformations coincides with the identity component of the isometry group.
Regardless of whether we use diffeomorphisms, it is a standard exercise in differential geometry to prove that affine maps are determined entirely by their value and derivative at a single point, so the dimension of $\mathcal{H}$ will be at most $\dim(M)+\dim(M)^2$.
It isn’t a very cohesive space most of the time, though: it will always contain both a copy of $M$ (the constant maps) and the identity map, and a path between a constant map and the identity would constitute a homotopy, which can only occur for $M$ contractible. Thus, in the generic case, it’ll probably just be $M$ together with an isolated point corresponding to the identity map.
In the Lie groups case, it’s essentially the same.
Note that if $f$ satisfies the condition, then so does $\mathrm{L}_g\circ f$. Thus, $f$ is of the form $\mathrm{L}_g\circ f_0$, where $f_0$ fixes a point, which we will predictably choose to be $e$. I think it follows that the space you end up with will be something like $G\times\mathrm{Hom}(G,G)$. Again, this won’t naturally be a Lie group outside of the discrete case, but if we restrict to diffeomorphisms, I think we get the Lie group $G\rtimes\mathrm{Aut}(G)$.