I was asked to find the right inverse of this function :
$g : \mathbb{R} \times \mathbb{R} \to \mathbb{R}$
$g\left(r, s\right) = rs$
I know that a right inverse exists since the function $g\left(r,s\right)$ is surjective.
I said that such an inverse would be:
$f : \mathbb{R} \times \mathbb{R} \to \mathbb{R}$
$f : \left(r,s\right) = \left(r,s\right)$
so that $g \circ f\left(r,s\right) = g\left(\left(r,s\right)\right) = rs$
Am I allowed to do this ? If not, how would I find this inverse?
In principle, yes, the inverse can be the function itself. Consider the function $h : \newcommand{\R}{\mathbb{R}} \R \setminus \{0\} \to \R \setminus \{0\}$ given by $h(x) = 1/x$. Clearly, $h(h(x)) = x$, so $h = h^{-1}$. In fact, we have a special name for such functions, involutions.
However, note that a function $h : A \to B$ will have (if invertible) an inverse function $h^{-1} : B \to A$; that is, the domain and codomain switch. Hence, a function $h$ cannot be an involution unless $\operatorname{domain}(h) = \operatorname{codomain}(h)$.
This also shows why your example does not work: your original function $g$, and your proposed inverse $f$, have the same domains and codomains: they need to be swapped. That is, you need
The error is compounded by claiming that $f(r,s)=(r,s)$: $(r,s)$ is a point in $\R \times \R$, not in $\R$, so you're also now suggesting that $\operatorname{codomain}(f) = \R \times \R$, inconsistent with previous claims.
How do we rectify this? Well, we want a function $f : \R \to \R \times \R$ that "undoes" $g : \R \times \R \to \R$ given by $g(r,s) = rs$.
This idea of "undoing" is key. If we want a right inverse to $g$, we want $(g \circ f)(x) = g(f(x)) = x$, for any $x \in \R$. (Again, note that we're using just $x$, since the domain of $f$ and hence $g\circ f$ is $\R$.)
So we ask ourselves: suppose that $f(x)=(a,b)$. What must $a,b$ be such that $g(f(x))=g(a,b)=x$? Well,
$$x = g(a,b) = ab$$
Hence, we want $ab=x$. Any $a,b$ fitting this will do; sometimes many candidates arise for inverses. The obvious, to me, would be to use $a=x^2$ and $b=1/x$ for $x \ne 0$, and $a=b=0$ when $x=0$.
That is, we say that
$$f(x) := \begin{cases} \displaystyle \left( x^2 , \frac 1 x \right), & x \ne 0 \\ \displaystyle (0,0), & x = 0 \end{cases}$$
Does this work? We need to be sure that $g(f(x))=x$. (Clearly, at least the function is well-defined as a function $\R \to \R \times \R$.) Observe that, for $x \ne 0$,
$$g(f(x)) = g \left( x^2 , \frac 1 x \right) = x^2 \cdot \frac 1 x = x$$
as desired. For $x = 0$,
$$g(f(0)) = g(0,0) = 0 \cdot 0 = 0$$
also as desired.
Hence, this is a suitable inverse.