I don't know how you stop it. fans who want to rush the court will do so - unless there is an overwhelming police presence. I suppose you could bring back the cages.
true fact - the reason basketball players were called "cagers" is because a number of courts - mostly at Eastern gyms - used to be enclosed in rope or wire cages. initially the reason for the cage was to keep the ball from going into the stands. but it was also considered a safety measure to keep players and fans from getting into altercations. the practice ended in the early 1930's but the name "cagers" stuck around.
here is a news clipping from the era:
"In some cities of the New York State League, gladiatorial combats of the ancient Romans pale into insignificance compared with the rowdyism rampant among some of the fans and some of the players. No effort on the part of the managers to curtail such tactics has apparently been made, with the results that the good old indoor game is getting into disrepute. The games are not fit places on some occasions to take a lady, certainly not the sort of contest they should like to witness."