How does a washing machine motor changes its direction after one cycle? I have the basic idea that a switch has to do something with it but want to know what exactly happens and how.
What vintage of washing machine? One of the old-fashioned "white goods" variety or something modern?
Old-fashioned washing machine motors often ran in one direction for agitation and the other direction for spin dry. This is done by having two windings in the motor. These motors are induction motors, most often seen having a start winding and a run winding. If you reverse the phase on the start winding, the motor starts running in the opposite direction. Note that a centrifugal switch at the end of the motor disconnects the start winding when the motor reaches operating speed. There is usually a large non-polarized capacitor in series with the start winding to provide the required phase shift to cause the rotor to spin.
The motors in most old-fashioned washing machines is a little different from that described above in that the two windings are often identical. There is a non-polarized capacitor connected between the free ends of the windings. The motor spins one direction if you connect power to one winding and spins the other direction if you connect power to the other winding.
Note that the agitation in these old machines is done in the transmission.
Newer machines: way too many possibilities to mention. Note that the motor in new washing machines is under complete computer control. This allows the motor to run in either direction and at different speeds.
Long story short: more information from you is needed.
Drive motor in a washing machine usually has 3 wires (lets call them A, B and common). If the current is supplied to A + common, the motor turns one direction; if it is supplied to B + common, the motor turns in opposite direction. Picture (notice the switch on the left): washing machine motor diagram
The switch is controlled by a timing circuit which basically does something similar to: '10 seconds CW, 5 seconds off, 10 seconds CCW, 5 seconds off, repeat'. In the very old washing machines, this was done with a timing motor, disks with cutouts and microswitches; later models used transistor timer; modern machines use microcontroller. Here is an example: transistor agitator timer. Note that RL/1 turns motor on/off, while RL/2 sets motor direction.