The moment the ball leaves the attacking side's feet (either a shoot or a pass) his teammates aren't allowed to be in a position farther than the last defender. Or even if it's not a pass, when the players stand in front of the linesight of the GK or stand in a position that changes the flow of the play it can still counts as offside.
I can't explain things well with words but I guess you'll understand it if you watch some videos about it
That's why the timing becomes important. The striker have to read the sign, his surroundings the movements of the defenders and then match his run with the movement of the passer, and vise versa.
I need to know soccer better, but why did his goal not count? After he finally made one?!