There are two parts to a player being offside and the opposition team being awarded a free kick as a result.
The first part relates to whether the player is offside when their teammate kicks the ball. The second part is whether the offside player is involved in the play.
In this animation, the player touches the ball after being in their forward half and closer to the goal line than the second last defender when their teammate kicked the ball, so a free kick will be awarded to the opposition.
Offside or not?
Is the yellow player at the top in an offside position when their teammate kicks the ball?
Forward half = Yes
Closer to goal line than second last defender = No
Allowed to play the ball when they receive it = Yes
The yellow player at the top is in an offside position when the ball is first played.
They are still in an offside position when the ball is kicked into the goal by their yellow teammate who was onside when the ball was first played.
The yellow player at the top does not touch the ball, they do not stop any red player from playing the ball, and they are not blocking the goalkeepers' view of the ball.
Therefore, the yellow player at the top is offside but not involved in play = no freekick = goal is awarded.