When there is no offside…
In order for there to be no offside in a play, the player receiving the ball from their teammate must be covered by two opponents at the moment they receive the pass. In most cases, one of the covering opponents is the goalkeeper, but it is not necessary for them to be one of the two.
However, the rules have four exceptions where no player needs to cover the receiving player. One of these is if the player was behind the halfway line when the ball was passed to them, while the other three arise from set-piece situations.
These exceptions include the throw-in, the goal kick (which can be taken by any player of the team), and the corner kick. In the latter case, one might argue that the ball is already in line with the goal, but this is not always the case, as the kicker can place it anywhere along the corner arc instead of always on the goal line.