I have to agree with
@Daniel D., it's almost always a safety switch.
On a lot of these compact tractors, you have a clutch switch and a seat switch that kill the engine if certain conditions aren't met.
In your case, it seems to be an issue with the clutch pedal switch.
If the switch is out of alignment or faulty, the tractor thinks the clutch is not fully depressed when you try to put it in gear, so it kills the engine.
It's a safety feature to prevent it from lurching forward.
Try checking the wiring and the position of the switch on the clutch pedal.
It's usually a pretty simple fix, sometimes just a little adjustment is all it takes.