Gates said he is leaving to become a deputy assistant attorney general in the Justice Department’s civil rights division.