Only about half of those voting the general election voted in the primaries. The other half (far, far more than the margin that Trump won over Clinton by) had yet to make their choice known by then.
Further, if Sanders had gotten the Democratic nomination, the debates, issues, and media coverage would have been far different, perhaps even swaying those who had wound up casting an anti-Clinton vote by voting for Trump to instead vote for Sanders.
One other thing to keep in mind that the turnout for Trump may have been much smaller had his opponent not been Clinton.
Further, if Sanders had gotten the Democratic nomination, the debates, issues, and media coverage would have been far different, perhaps even swaying those who had wound up casting an anti-Clinton vote by voting for Trump to instead vote for Sanders.
One other thing to keep in mind that the turnout for Trump may have been much smaller had his opponent not been Clinton.