If I play my Illusory Gains on my opponent's commander, does their commander become mine indefinitely? I have not played this card and I am unsure as to how playing it on a commander works.
You control that player's commander until another creature enters the battlefield under an opponent's control. At that point, Illusory Gains moves to that creature, and the owner regains control of their commander.
No, because change of control effects are continuous effects, not one-shot effects. The controller is only changed as long as the continuous effect changes it.
Control of a permanent is continually evaluated based on who placed the object on the battlefield and any continuous effects overriding that.
Let's look at a more intuitive continuous effect for a moment. If your opponent has a creature that has a default power/toughness of 3/4, and you create a continuous effect that gives it -2/-2, the creature will revert to being a 3/4 when the continuous effect ends.
Similarly, if your opponent has a creature and you create a continuous effect that changes its controller, the creature will revert to your opponent's control when the continuous effect ends.
The way Illusory Gains works has been answered by others, but I thought I'd tackle the Commander bit.
Commanders become new objects when they change zones just like any other card
The only thing that Commanders "remember" is that they are their owner's commander.
903.3. Each deck has a legendary creature card designated as its commander. This designation is not a characteristic of the object represented by the card; rather, it is an attribute of the card itself. The card retains this designation even when it changes zones.
Example: A commander that’s been turned face down (due to Ixidron’s effect, for example) is still a commander. A commander that’s copying another card (due to Cytoshape’s effect, for example) is still a commander. A permanent that’s copying a commander (such as a Body Double, for example, copying a commander in a player’s graveyard) is not a commander.
Other than that, (and the special rule that allows you to return a Commander to the Command zone if it changes zones), the Commander behaves just like any other creature (or planewalker) in the game. If it leaves play, it will "forget" any and all effects that were modifying how it behaved.