What happens in football if a player shoots the ball and the ball goes in the goal after deflecting off the referee? As far as I know it is given as a goal, but are there any other consequences?
According to old FIFA Law 9: The ball in and out play:
If, when the ball is in play, it touches the referee or an assistant referee who is temporary on the field of play, play continues because the referee and the assistant referees are part of the match. (emphasis mine)
If a ball is deflected bouncing off a referee and goes into the goal, it's a goal in the same way a goal is scored when a ball is bounced off a goalpost or crossbar and goes into the goal.
According to Law 9, 2. Ball in play of the new IFAB Laws:
The ball is in play at all other times, including when it rebounds off a match official, goalpost, crossbar or corner flagpost and remains in the field of play.
It happens very rarely, especially in a professional football game, because referees are trained well enough to be in a position where there is a very little chance of a ball touching them. Even if it happens, the game will go on.
Here is an instance of a referee "scoring" a goal. There was much protest from the defending side but the goal stood.
The referee in that match was José de Assis Aragão.
In the 1983 championship José de Assis Aragão refereed a Santos versus Palmeiras match in the Morumbi stadium. Santos lead by 2-1, but in the second minute of extra time there was a scrimmage in the Santos penalty box, the ball cannoned between legs and by accident the last leg it hit before ending up in the goal was the referee's. Aragão validated the goal correctly despite a lot of predictable complaints by the Santos side.
So the referee did the right thing in awarding the goal.