Nij's answer sums up the general principles and the correct outcome. I will attempt to answers based strictly on the Laws.
Law 10 - Determining the Outcome of a Match, Section 1 - Goal Scored:
A goal is scored when the whole of the ball passes over the goal line, between the goalposts and under the crossbar, provided that no offence has been committed by the team scoring the goal.
Law 5 - The Referee, Section 2 - Decisions of the Referee:
The referee may not change a decision on realising that it is incorrect or on the advice of another match official if play has restarted or the referee has signalled the end of the first or second half (including extra time) and left the field of play or terminated the match.
Technically, a team should not be allowed to score a goal if they have committed an offence since the last restart of play. The VAR adds a new dimension in that decisions that all on-field officials have already ruled on may end up being changed, but the underlying principle is still effectively the same.
Consider the following example that could already occur without VAR (and obviously at a level where the match officials don't have comms gear):
- The red team loses the ball in the blue team's penalty area, with a red striker landing on the ground after a strong, but fair tackle.
- The blue team clears the ball to the blue attackers, who end up in a strong attacking position
- The blue goalkeeper takes exception to the red striker, believing he has dived, and kicks him within blue's penalty area.
- This is flagged by the AR in blue's half, but the referee misses it as he is in position to monitor blue's attack and has his back to the AR.
- Meanwhile the blue attack develops, leading to a goal.
- Before restarting play, the referee notices the flag from the AR, cancels the goal awards a penalty kick to red, and sends off the blue goalkeeper for violent conduct
As you can see, nothing has really changed here, other than the possibility of far more decisions being changed after they were initially decided on and/or missed. Having said that, the example provided in your question is unlikely to occur - according to IFAB's VAR Protocol:
If the referee wants a review when play has not stopped, play should be stopped as soon as it is in a ‘neutral’ area i.e. when neither team has a good attacking possibility.
Unless it is an extremely quick counter attack, the referee would probably stop play before a goal was scored up the other end.