Here is a higher-level description of this operation, mostly from the perspective of Hopf algebras. You'll have to decide yourself how "functorial" this is.
Let $R$ be commutative ring and $G$ be a group. (Usually we have $R=\Bbb Z$ in group cohomology and $R$ a field in representation theory.) Then $R[G]$-modules are the same as $R$-modules together with a $R$-linear action of $G$. (Unless mentioned otherwise, all modules will be left modules)
As usual, we denote by $M^G$ the invariants of $M$ under $G$, this is a $R$-module.
Then for $R[G]$-modules $M$ and $N$, we can make $\operatorname{Hom}_R(M,N)$ into a $R[G]$-module by defining $(gf) (m) :=gf(g^{-1}m)$. This definition has the nice property that we have $(\operatorname{Hom}_R(M,N))^G=\operatorname{Hom}_{R[G]}(M,N)$
We can motivate this action by using the natural Hopf-Algebra structure on $R[G]$:
Suppose for a moment that only $N$ is $R[G]$-module and $M$ is just a $R$-module, then the obvious choice for a $R[G]$-module structure on $\operatorname{Hom}_R(M,N)$ is induced by the $G$-action $(gf)(m):=g\cdot f(m)$
(If you want to describe this in a difficult way, you might say that we always have a canonical left monoid action of $\operatorname{End}_C(N)$ on $\operatorname{Hom}_C(M,N)$ (where $C$ is any category) just given by composition. The $R[G]$-module structure on $N$ is equivalent to a monoid homomorphism $G \to \operatorname{End}_R(N)$ and this action of $G$ on the Homset is just obtained as a composition of these two actions.)
Now suppose we have the dual situation that only $M$ is a $R[G]$-module and $N$ is a $R$-module, then we still have a natural action of $G$ on $\operatorname{Hom}_R(M,N)$ given by $(gf)(m)=f(gm)$, but the problem, which arises essentially from the contravariance of the Hom functor in the first argument, is that this is a right action, not a left action. (Dual descriptions of this as the composition of the monoid homomorphism $G \to \operatorname{End}_R(M)$ and the natural action of the endomorphism monoid apply.)
If we still want to stay in the category of left modules, the antipode map of the Hopf algebra $R[G]$ saves us. (The antipode map $S:R[G] \to R[G]$ is induced by the inversion $G \to G, g \mapsto g^{-1}$)
The antipode map is an antihomomorphism, so if we compose with the antipode map, we can turn this right action into a left action.
Explicitly, this turns out to give us the action $(gf)(m):=f(g^{-1}m)$, but this is just we obtained by using what we were given in an abstract setting.
Now suppose that indeed both $M$ and $N$ are $R[G]$-modules and we want to find the "correct" $G$-action on $\operatorname{Hom}_R(M,N)$. We could of course just ignore that $M$ is a $R[G]$-module and use the action that we have described in this case. We could also ignore that $N$ is a $R[G]$-module and use the action we have described for that case. This gives two different $R[G]$-module structures on $\operatorname{Hom}_R(M,N)$, or to put it differently, we get two different ring homomorphisms $R[G] \to \operatorname{End}_{\Bbb Z}(\operatorname{Hom}_R(M,N))$, since these actions commute pairwise and agree on $R \subset R[G]$, we get an induced ring homomorphism $R[G] \otimes_R R[G] \to \operatorname{End}_{\Bbb Z}(\operatorname{Hom}_R(M,N))$, this means that $\operatorname{Hom}_R(M,N)$ is a $R[G] \otimes_R R[G]$-module. But since $R[G]$ is a Hopf-algebra, we have the comultiplication map $\Delta: R[G] \to R[G] \otimes_R R[G]$ which is a $R$-algebra morphism. Composing the $R[G] \otimes_R R[G]$ action with the comultiplication map gives us the $R[G]$-module structure described in the beginning.
Now that we have obtained the nice $R[G]$-module structure on $\operatorname{Hom}_R(M,N)$ with the easily checked property that $(\operatorname{Hom}_R(M,N))^G=\operatorname{Hom}_{R[G]}(M,N)$, the task of describing a canonical map $\operatorname{Hom}_R(M,N) \to \operatorname{Hom}_{R[G]}(M,N)$ is just a special case of describing a canonical map $X \to X^G$, where $X$ is a $R[G]$-module.
It's not difficult to see, that if we view $R$ as a $R[G]$-module with the trivial action (that is, via the counit $\varepsilon:R[G] \to R$), then
$X^G=\operatorname{Hom}_{R[G]}(R,X)$ of course, we also have $X=\operatorname{Hom}_{R[G]}(R[G],X)$, so describing a map $X \to X^G$ is the same as describing a map $\operatorname{Hom}_{R[G]}(R[G],X) \to \operatorname{Hom}_{R[G]}(R,X)$
If we just had one $R[G]$-linear map $N:R \to R[G]$, then we could obtain such a map just by applying the functor $\operatorname{Hom}_{R[G]}(-,X)$ to that. (And by Yoneda, that is the only natural way to do it.)
If we take the same map for all $X$, then this also gives us a naturality in $X$ easily, since everything is just obtained by precomposition with a morphism on homsets.
We have $\operatorname{Hom}_{R[G]}(R,R[G])=R[G]^G$.
If $G$ is an infinite group, then $R[G]^G=\{0\}$, so there's nothing nontrivial we can do with this approach.
But if $G$ is finite, then one finds that $R[G]^G$ is generated by the element $N_G=\sum_{g \in G} g$ as an $R$-module. (I don't have an abstract explanation for this, this is just an easy computation you have to do)
So choosing a $R[G]$-linear map $R \to R[G]$ is equivalent to choosing some $R$-multiple of $N_G$. Of course, we could just choose $N_G$ itself (this is what is usually done in group cohomology, it allows you to relate this stuff to the norm and trace maps from field theory if you apply it where $G$ is a Galois group.), but there is another requirement that makes a certain choice more natural than others.
It would be nice if we could choose the morphism $R \to R[G]$ in such a way that the composition $R \to R[G] \xrightarrow{\varepsilon} R$ is the identity on $R$, where $\varepsilon: R[G] \to R$ is the counit from the Hopf algebra structure. It's not always possible to do this, but it works if $|G|$ is invertible in $R$, then we can take $R \to R[G]$ as multiplication with $\frac{1}{|G|} N_G$, this is the unique $R[G]$-linear map $R \to R[G]$ with this property, or in other words, the unique section of the counit $R[G] \xrightarrow{\varepsilon} R$ in the category of $R[G]$-modules.
Assume that this is possible in the following. (Other choices will still give you natural maps $X \to X^G$)
Putting everything together, we obtain a family of maps $X \to X^G$ and if we set $X=\operatorname{Hom}_{R}(M,N)$ for two $R[G]$-modules $M$ and $N$, then we get the map $\operatorname{Hom}_R(M,N) \to \operatorname{Hom}_{R[G]}(M,N), f \mapsto (x \mapsto \frac{1}{|G|}\sum_{g \in G}gf(g^{-1}x))$
The requirement we put on the composition $R \to R[G] \xrightarrow{\varepsilon} R$ turns into a property that is crucial in the proof of Maschke's theorem, namely that if we put $M=N$, then the map $\operatorname{Hom}_R(M,M) \to \operatorname{Hom}_{R[G]}(M,M)$ maps the identity to the identity.
As for naturality in $G$, I'm not sure how to make it work in the most general setting, but we have some kind of "naturality" for exact sequences of finite groups:
If $G$ is finite and $|G|$ is invertible in $R$ and $H \lhd G$ is a normal subgroup, then we get that $X^H$ is a $R[G/H]$-module and we have $(X^H)^{G/H}=X^G$ and if we compose the maps
$X \to X^H, x \mapsto \sum_{h \in H} \frac{1}{|H|} \sum_{h \in H} h\cdot x$ and $X^H \to (X^{H})^{G/H}=X^G, x \mapsto \frac{1}{|G/H|} \sum_{\overline{g} \in G/H} g \cdot x$, then we get the map
$X \to X^G, x \mapsto \frac{1}{|G|}\sum_{g \in G} gx$ (Compare this map to "corestriction" from group cohomology)