Mary Bassett, who as New York City’s top doctor has navigated epidemics and outbreaks, tried to narrow health inequities and, most recently, fielded questions over the city’s handling of lead exposure in children, announced Thursday she is leaving the de Blasio administration at the end of the month for a job at Harvard.