A player in an offside position at the moment the ball is played or touched* by a team-mate is only penalised on becoming involved in active play by:
gaining an advantage by playing the ball or interfering with an opponent when it has:
rebounded or been deflected off the goalpost, crossbar or...