its easy to stop this. they just have to impose a 1 year prison sentence for any fan that comes onto the court.
until they do something like this, there will always be nutjobs coming onto the court
as they know they hardly will get punished at all
it cant be done easily, if at all. prison time is a punishment for a committed crime and as such can only be proscribed by a sovereign state that has a monopoly of force over its territory. usually these types of 'universal' crimes are proscribed by an international convention, but still each state (member of the convention) individually incorporates it into its legal system and that takes time. and those crimes are the worst crimes (war crimes, crimes against humanity, genocide...). hard to imagine an international convention to be made for a particular sport that would oblige states to make it a law.
what can be done is for governing body (atp, itf, wta) to proscribe like a ban from attending tournaments under its jurisdiction but its not a punishment the type of prison obviously. this is also questionable because there would have to be a tracking system for those offenders to keep them away from tournaments, and this would perhaps violate some human rights concerning with privacy of personal related information.