first you need to do a lil diagnostics to see what may be a root cause.
with machine off. grab the lil pto stub at the back of the tractor. pul and push on it inand out of the housing. is there any in / out play? that will be thrust play and is a prime cause of pto walkin gitself out of engagement. thrust play can come from a bad bearing, slipped wear ring, broke or slipped out split ring, and or damaged bearing carrier housing.
also check for bearing play ( side play ).
if there is thrust play. drain oil or jack up the rear / drop the front and pull the pto shaft.
4 bolt job.
once you get the shaft assy out. damage will be evident.
if the bearing carrier is broke or the split ring has popepd out.. you might want a complete replacement assy vs just the bearing carrier.
also.. many times when the split rings pop out.. they shave the lip on the carrier so that they will no longer stay seated.. and / or the ring edges get worn.. do the same.. slip out more.
if you do piece it.. get a new seal and wear ring.. etc. gased can be bought or made of thin gasket paper.
post back.
if it is not thrust play.. it may be a bad detent.. or shifter is not moving it into engagement enough.
can check that out at the side cover with the shifter.
plenty of other issues.. but these are the EZ ones to check first.