Anna this is the error you found when fg=gf in terms of function composition:

{f,g}={1/x,Sqrt[x]}

Subtract them fg-gf and Mathematica does not give you 0 though fg=gf

(f/.{x->g})-(g/.{x->f})

(f/.{x->g})-(g/.{x->f})==0

However if you expand the powers you get 0:

PowerExpand[(f/.{x->g})-(g/.{x->f})]

This our code to solve the problem:

data=<|
"a"->{

{Sin[x]^2,x∈Reals&&-10<=x<=100, y∈Reals&&-1<=y≤(1-0.00000001),ToString[Sin["x"]^2,TraditionalForm]},
{Sin[x]^2,x∈Reals&&-10<=x<=100, y∈Reals&&0<=y≤(1-0.00000001),ToString[Sin["x"]^2,TraditionalForm]},

{Sin[x],x∈Reals&&-10<=x<=100, y∈Reals&&-1<=y≤(1-0.00000001),ToString[Sin["x"],TraditionalForm]},
{Sin[x],x∈Reals&&-10<=x<=100, y∈Reals&&-2<=y≤(2-0.00000001),ToString[Sin["x"],TraditionalForm]},

{Cos[x]^2,x∈Reals&&-10<=x<=100, y∈Reals&&-1<=y≤(1-0.00000001),ToString[Sin["x"]^2,TraditionalForm]},
{Cos[x]^2,x∈Reals&&-10<=x<=100, y∈Reals&&0<=y≤(1-0.00000001),ToString[Sin["x"]^2,TraditionalForm]},

{Cos[x],x∈Reals&&-10<=x<=100, y∈Reals&&-1<=y≤(1-0.00000001),ToString[Sin["x"],TraditionalForm]},
{Cos[x],x∈Reals&&-10<=x<=100, y∈Reals&&-2<=y≤(2-0.00000001),ToString[Sin["x"],TraditionalForm]},

{Abs[x]^(1/2),x∈Reals&&-1<=x<=1 ,y∈Reals&&0<=y≤(1-0.00000001),ToString[Abs["x"]^(1/2),TraditionalForm]},

{Abs[x]^(1/2),x∈Reals&&0<=x<=1 ,y∈Reals&&0<=y≤(1-0.00000001),ToString[Abs["x"]^(1/2),TraditionalForm]},

{Abs[x],x∈Reals&&-1<=x<=1 ,y∈Reals&&0<=y≤(1-0.00000001),ToString[Abs["x"]^(1/2),TraditionalForm]},

{Abs[x],x∈Reals&&0<=x<=1 ,y∈Reals&&0<=y≤(1-0.00000001),ToString[Abs["x"],TraditionalForm]},

{x^nn,x∈Reals&&-10<=x<=10 ,y∈Reals&&((-10)^nn)<=y≤((10^nn)-0.00000001),ToString["x"^nn,TraditionalForm]},

{x^(1/nn),x∈Reals&&0<=x<=1 ,y∈Reals&&0<=y≤(1^(1/nn)-0.00000001),ToString["x"^(1/nn),TraditionalForm]},

{nn*x+1,x∈Reals&&0<=x<=10 ,y∈Reals&&1<=y≤(10*nn-0.00000001),ToString[nn*"x"+1,TraditionalForm]}
}
,
"b"->{Sin[x],Cos[x],x^nn,x^(1/nn),nn^x,x*Sin[x],x*Cos[x],1/x}
|>;

Look at While statement

{f,g}={1/x,Sqrt[x]};
h=RandomChoice@{{f/.{x->g},True},{g/.{x->f},False},{ f*g,False}};

While[PowerExpand[(f/.{x->g})-(g/.{x->f})]==0 ||PowerExpand[(f/.{x->g})-f*g]==0|| TrigExpand[(f/.{x->g})-(g/.{x->f})]==0 ||TrigExpand[(f/.{x->g})-f*g]==0,
{f,g}=(RandomSample[(data["b"]),2])/.{nn->n};   (* x cannot be a part of the local vars list*)

h=RandomChoice@{{f/.{x->g},True},{g/.{x->f},False},{ f*g,False}};];

h