“Gaining advantage” is one of three ways in which a player can be penalized for being in an offside position. This happens, for example, when a player who was in an offside position plays the ball after the ball had deflected off from the goal post. Or the goal keeper may save the ball and the ball travels to the attacking player who was originally in an offside position.
Sometimes, the attacking player was not in an offside position when the ball was last touched by their teammate. But they may be in an offside position when the deflection or the save happened. This can lead to an error if the assistant referee forgets or does not recognize that the player was originally onside.
Both good focus and proper positioning are important to avoid such a mistake. In the video below, an attacking player who was clearly onside was penalized for offside. The assistant referee was not properly positioned. When the goal keeper saved the ball, the attacker is in an offside position. However, she was originally onside.