I think a lot of it was the campaign Clinton ran. She has assumed from Day 1 that she was entitled to be president, that she should be anointed, because it was her turn and she was a woman, by golly, and she ran her campaign that way from start to finish. She didn't work hard enough for it, presumed too much in too many states, and didn't fire up the marginal liberal-leaning votes in key metro areas. Plus, I suspect that there is more to the health issue than she or anyone else let on during the campaign. I don't think she's particularly well health-wise, and maybe that played into her lack of enthusiasm for the race.
Also, nobody has given Trump credit for the campaign he has run. Early on, he sensed the mood of the country and he played to that mood relentlessly. So what started out as a joke became a movement, and he and his people were right at every step along the way.