One who is outside the line does not count in the game. Infact the game has to be stopped to bring him back into the game, he cannot even enter the game just like that after receiving treatment.
So the goal was a lucky off-side goal. Bad decision by the linesman.