As per Law 10 of the FIFA Laws of the Game:
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 infringement of the Laws of the Game has been committed previously by the team scoring the goal.
There is no requirement that the ball needs to touch the net for it to be counted as a goal. In fact, a net is not a mandatory requirement in order for a game to be played, as per Law 1 (emphasis mine):
Nets MAY be attached to the goals and the ground behind the goal, provided that they are properly supported and do not interfere with the goalkeeper.
Obviously though, there will be a net 99% of the time as it helps EVERYONE to see that a goal has been scored (most of the time).
It is either the referee or assistant referees job to conduct a check of the nets always before the game. By having the nets not secured properly or with holes in them, it just makes their own job much more harder. EG) A ball enters the goal through a hole in the side of the net when going out for a goal kick.
Hope this answers your question. In 11 years of refereeing, I quickly learnt to check the nets before every game after this kind of incident happened to me.