Trump capitalized on a rare opportunity, a huge number of bland establishment candidates who divided support from the moderates. Trump embraced and galvanized the RWNJ faction who were (often rightly) disenfranchised by the moderates, meanwhile the moderates could never sort out which milquetoast candidate to back. That won him the nomination.
Then Clinton, a terrible candidate who may have been the only person who could have lost to Trump made a bunch of errors allowing Trump's campaign to flip those rust-belt states. The DNC owns some of the blame here for their long term strategy in those states (or lack of). The RNC also are reaping the fruits of having spent years whipping up the loonies in their party.