It's not offside if the player isn't interfering with play, interfering with an opponent or gaining an advantage by being in an offside position. They're very broad definitions and what gets given and what doesn't can vary according to the refereeing team - both in game and in real life.
So in the OP, was there a player distracting the goalkeeper or in the goalkeeper's line of vision, whether directly or peripheral (interfering with an opponent part of the rule)? If so, if that player was offside, the goal can be cancelled out.