It is not a usual thing for a referee to score a goal no matter the situation. Although they might cause deflections which can lead to a goal.
In such a situation, the goal shouldn’t be counted. Throughout the history of football, there is a record of two situations where a referee scored a goal and it was counted.
Many people during that era were actually very sad and were against the action. Below are the two referees and the story of what happened.
1. Maurice Paahius
He is a Dutch referee. He accidentally scored a goal during a Dutch soccer game. After he scored the goal, he refused to disallow it.
2. Brian Savill
The story of this event happened in September 2001. During the match, the referee named Brian Savill was refereeing a Great Bromley Cup tie between Earls Colne and Wimpole 2000 and shoot the ball into the net to score for Wimpole.
At one stage of the match, Earls Colne Reserves were up 18-1 in the match. When Wimpole 2000 was given a corner, Brian Saville had had enough and felt sorry for the team that was loosing. He deflected the ball into the net and celebrated with them.
Surprisingly, the referee awarded the goal. The match finished at 20-2, in favour of Earls Colne.