First of all, since g(f(x))=x3 and x3 is injective, f is injective. Indeed,
f(x)=f(y)⟹g(f(x))=g(f(y))⟺x3=y3⟺x=y. Plugging
f(x) in f(g(x))=x2, we obtain f(g(f(x)))=f(x)2⟺f(x3)=f(x)2. If
f,g:R→R, consider x=−1,0,1 (i.e., the roots of x3=x): f(−1)=f(−1)2,
f(0)=f(0)2 and f(1)=f(1)2, so {f(−1),f(0),f(1)}⊂{0,1}, which
contradicts the fact that f is injective. So in this case there are no such
functions f,g.
If f,g:S→S, consider f(x3)=(f(x))2 and g(f(g(x)))=(g(x))3⟺
g(x2)=(g(x))3. Applying these two identities n times we obtain f(x3n)=
(f(x))2n and g(x2n)=(g(x))3n. In particular, f(23n)=(f(2))2n and
g(22n)=(g(2))3n. Extend these identities for all n real. We have x=
23n⟺n=log32log2x and x=22n⟺n=log2log2x. This means
that f(x)=a2log32log2x and g(x)=b2log22log2x. For the sake of simplicity, write all
equations in base 2: f(x)=22log32log2log2x+k and g(x)=22log23log2log2x+ℓ.
Now substitute in the original equations:
f(g(x))=f(22log23log2log2x+ℓ)=22log32log2log222log23log2log2x+ℓ+k=22log32⋅(log23log2log2x+ℓ)+k=22log2log2x+ℓlog32+k=22log2log2x⋅2ℓlog32+k=(22log2log2x)2ℓlog32+k=x2ℓlog32+k
so 2ℓlog32+k=2⟺ℓlog32+k=1.
g(f(x))=g(22log32log2log2x+k)=22log23log2log222log32log2log2x+k+ℓ=22log23⋅(log32log2log2x+k)+ℓ=22log2log2x+klog23+ℓ=22log2log2x⋅2klog23+ℓ=(22log2log2x)2klog23+ℓ=x2klog23+ℓ
so 2klog23+ℓ=3⟺klog23+ℓ=log23.
It is clear that both f and g are well defined in S and that it's possible to
choose k and ℓ (for example, k=1 and ℓ=0), so such functions do exist.