On a 520, there are some small black, square relays plugged into the wiring harness. These regulate the safety system, charging system and ignition systems. If one of these relays are bad, then it could be causing your problem.
Also you could be having an electronic ignition that is going bad. You also could have a short in one of the plug wires. This is usually caused by insulation being damaged ..usually this is caused by a mouse that has gotten inside the engine and built a nest and eating the rubber off of the wires. Remove the engine cover and check to see if there is a mouse nest in it. Also check ALL of the wires for bare spots.
Also you could have any one of several safety switches that may be working intermittently.
If you don't feel comfortable with this kind of repair I would suggest sending it to a reputable shop.
In order to test the ignition, It will have to be taken to a GOOD shop. Preferably the whole tractor. When I mean a GOOD shop, I mean one that has all the latest test equipment. Most shops DO NOT have the latest equipment...because it is very expensive.
Most people just end up buying the ignition and hope it works.
You could still have something else that is causing the problem, but it is very hard to find out what it is without actually having it here and testing it. Electrical problems can be very elusive....even for good shops to figure out.
Good luck, I hope I have helped...at least a little bit.
The first thing that you want to check is to make sure that the carburetor throttle shaft is not stuck. This usually happens if the engine has been sitting for quite awhile. It gums up and won't move. If it is stuck, you may have to clean the carburetor...or at least spray some spray carburetor on the outside and inside of the carburetor on the throttle shaft. IF it won't fee up then you will have to re move the carburetor and rebuild it.
If that is not the case, you should look to make sure that the linkage is not catching on something. This can cause your problem.
Next you want to find the governor shaft and make sure that the shaft is not turning inside the governor arm. If it is loose, it will cause the engine to race and will have to be ...not only tightened...but the Governor will have to be "SET"
IF that is not the trouble, you may have a governor gear broken inside the engine. We will hope that this is not the case because it requires that the engine be torn down and the gears checked and maybe replaced. Then the governor will have to be "set ".