A suburban rebellion against President Trump propelled Democrats to victory in races for governor, state legislature and mayor, in a series of elections.