Neutral drain is completely a mechanical function inside the transmission.
The spin gear is not driven in agitate direction. There are weighted and spring cams and levers in the transmission that set during agitation and function to lock the spin gear from turning when the motor first changes to the reverse direction after an agitation period ... when neutral drain begins.
The cams and levers release when the motor stops after drain. The spin gear then is driven when the motor restarts in the same direction (reversed from agitation) for spin, and the spin gear is driven.
A cam and gear on the agitate shaft also shift one way or the other to engage or disengage agitation, depending on which direction the motor & transmission are running.