The part that is important is T has a very specific effect, such as rotating three corner pieces, that doesn’t change most of the cube. Then you pick a g that doesn’t affect those pieces either (except in the way that you want) so that gTg’ does what you want.
It doesn’t work in general for any arbitrary T of course since it’s not commutative as you noted. This is more of a cubing thing than an algebra thing.
You are right that it is not really an algebra thing. It's a bijection between finite sets thing. If you apply a bijective mapping from set A onto set B, then apply some permutation to B, and then apply the inverse mapping, you get a permutation of A that has the same structure as the permutation you applied to B.
By "same structure" I mean that if written as a product of disjoint cycles has the same number and sizes of cycles.
Abstract algebra is probably the first place most people would encounter it though, in the context of conjugates in groups.
It doesn’t work in general for any arbitrary T of course since it’s not commutative as you noted. This is more of a cubing thing than an algebra thing.