A mix of different factors. Being anti-immigrant and having Steve Bannon help him to reach out to basically racist white voters fearful of a black takeover were two of them.
In addition, though, the basically successful economic policies that President Obama put in place in 2009 and 2010 to rescue the United States from a banking meltdown, a collapse in the real estate market and a serious recession initially helped Wall Street, the banking industry and big corporations -- like General Motors, for example -- much more directly than they helped ordinary Americans.
A lot of lower-income and middle income white people, and a lot of black and Hispanic Americans as well, still continued to hurt economically even as Obama's economic recovery proceeded. The amount of economic inequality in the United States, as measured by liberal economists such as Nobel prize-winner Joseph Stiglitz, actually increased as the economic recovery gathered steam. And Obama, although he had campaigned in 2008 as a skeptic of "free trade" policies, started to promote free trade treaties like the proposed Trans Pacific Partnership (TPP) toward the end of his second term.
Hillary Clinton at first strongly supported the "free trade," pro-globalization agenda, including the proposed TPP, only to then turn against it publicly toward the middle of her 2016 campaign for president.
Hillary had another problem, too: ever since she'd been Bill Clinton's First Lady when Bill was governor of Arkansas, she and Bill had been strongly associated with Wal-Mart and the big Arkansas-based chicken company Tyson Foods. During the 1980s and 1990s, Tyson and other companies like Tyson basically destroyed the economic independence of many American farmers, by turning them into little more than "share croppers" of big, vertically integrated meat producers.
It followed that many lower-income and middle-income Americans, especially white people living in somewhat depressed rural areas and industrial areas, really didn't like Hillary at all. And because she was seen as a champion of new immigrants, nonwhites, and sexual minorities like LBGTQ people, many rural Americans probably saw her as doing nothing for people like them. They chose Trump instead.
Also contributing to Hillary's loss in the Electoral College were the positions that Hillary and Obama had both taken in defense of a woman's right to abortion, which many religious conservatives saw as a sinful abomination.
And Obama's attempts to address Climate Change through his Clean Energy Plan at EPA -- although it was addressing an urgently important problem -- was poison to many traditional coal-mining communities that depend on the production of climate-wrecking fossil fuels. Trump promised to end Obama's so-called "War on Coal," and to the cost of future generations, his appointees to EPA have done a lot to fulfill that promise.
-- democratic socialist