So if I understand you correctly, you are using a hand spray wand connected to the on demand pump. When setting with the ATV off, Shortly after you start spraying, the pump starts to run and stays running untill you stop spraying then the pump stops shortly afteward. With the engine running, you start to spray and the pump cycles on and off rapidly while you are spraying.
Believe it or not, that actually sounds normal to me if your battery is a little weak/old. With the engine off, the pump pressurizes the system and shuts off. When you start to spray, the pressure drops and the pump turns on to try and make up the pressure. With the engine charging system not adding power to the battery, the voltage drops a bit and the pump is unable to keep up with the flow demands of the spray wand so the pump runs constantly and the pressure drops to a point that the pump can maintain. Since the pressure never reaches the shutoff point, the pump runs constantly. If you have a pressure gauge on your system, you will see that the pressure drops to a point and stays there. As the battery discharges, that pressure will get lower and lower. With the engine running and the battery being maintained at peak voltage, the pump is easilly able to meet the demand of the spray wand so it shuts off. Since the wand is still spraying, the pressure quickly drops below the turn-on point of the pump so it does and quickly boosts the pressure above the turnoff point.
How to fix this? It could be that the voltage regulator on your ATV has a problem and is not regualting properly. Do you have a volt meter? The regulator circuit of most ATV's/motorcycles should give an output of 14.5 VDC +/- 0.5 VDC even with the load of headlights and pump running. If you are getting more than this voltage measured at the battery with the pump running, you may have charging issues. It is also possible that the setpoint on the pump pressure switch is too low. If you don't have one, I would reccomend adding a pressure gauge "T"d to the pump output. If the switch is set below the pump rated maximum pressure, it might be possible to turn it up slightly so that the pump would have trouble reaching the shutoff pressure with the engine running when the wand is spraying as it does when the engine is shut off. Of course I DO NOT reccomend seting the switch above the maximum pressure rateing from the pump manufacturer as the pump could damage itself trying to reach this pressure when not spraying You could add a bigger spray nozzel so that the pump when connected to the running ATV is unable to meet the flow demand of the spray wand and still make the pressure go high enough to turn off the pump. You could add a pressure regulator to the pump output that maintains the output pressure below the switch setpoint and diverts the excess back to the tank. This would mean that the pump runs all the time. You would then manually turn it on when you want to spray and off when you don't. You could also switch to a lower volume pump that would be unable to maintain max pressure with full ATV charging voltage when the wand is spraying.