Why does my tractor pop out of gear?
It could be that the tractor has been shifted without coming to a complete stop (Yanmars are not synchronized) and the gears are just wore down & beveled. That grinding you hear is the sound of the teeth's edges getting ground down. If that is the case they may not be able to lock onto each other place and they just slip off.
It could also be that the shift fork is bent and is not engaging far enough to hold the two gears together.
It could also be that the detent spring is weak or broken and the detent ball is unable to hold the gear in place.