After the dyeing cycle is finished, run the dyed clothes through two additional washing cycles. If you've been using fiber reactive dyes, wash them in cold water first, then in hot water. With acid dyes, use cool water for both cycles.
Take out the dyed clothes.
Put some rags into the washing machine.
Run the machine through on a hot cycle, adding bleach instead of laundry detergent.
Run the machine through one final cycle, without adding any more bleach. Once the cycle is completed, the machine should be clean. You can use it to do the laundry without worrying about staining your clothes.