The offence was created by the Football Offences Act 1991. On the figures available, there have been less than a thousand arrests and prosecutions for going on to the pitch since 2010, none of which were for mass-jubilation events.
It is a defence to have a "lawful excuse". What is a "lawful excuse" hasn't been properly tested in the Courts as the only people ending up in the Courts don't have anything like a lawful excuse to argue; otherwise, on current practice they wouldn't be in Court in the first place - such as you get pushed over the fence and end up on the pitch during a goal celebration, or you need to move away from danger (an incident on the terrace).
The law was arguably designed to cover the morons who run on the pitch and attack the players or officials, and that is mostly how it has been used (borne out by the low prosecution figures since 2010). Streakers don't get prosecuted. People who celebrate an emotional moment with no hostile intent don't get prosecuted. However, there is nothing in the law that requires "hostile intent", technically the offence covers ANY encroachment. If the authorities started prosecuting more and using the law against your average fans who become overcome with emotion and run on the pitch after the final-whistle in their thousands, then some case-law would have to follow from the Courts to clearly define what exactly counts as a "lawful excuse".
One point to note, it only applies to designated football matches. Run on to a cricket pitch, or a rugby pitch, or a basketball court (even with hostile intent) does not in itself make you a criminal; step over the fence on to the pitch at a designated football match, you are technically then a criminal with all the consequences that entails. Since 1991 the authorities have used common sense. When common sense stops, then the law will need to be clarified by the Courts, because as someone has said, it would be nonsense to march 5,000+ average Argyle fans into Plymouth Magistrates Court for post-match celebrating Argyle being promoted to the Championship. Even if the Magistrates Court tolerated it, somewhere up the Appeal chain a senior Judge would see common sense and probably define "lawful excuse" as including post-match (after the final whistle) mass-celebrations of a compelling non-aggressive emotional event.