Trump lost because the Republican Party has reached the current limit of political popularity that it can have throughy open appeals to white racist resentment, white nationalism, anti-intellectualism, anti-urban feelings, conspiracy theories, and various other dubious emotions or stances. Trump lost because even some otherwise Republican leaning voters looked at Trump's general corruption and specific ineptitude combating the coronavirus pandemic and decided that enough was enough.
Trump lost because his support slipped among white men, his most devoted base. Trump lost because he is congenitally unable to frame appeals to people that are not rooted in hate. Trump lost because he's unwilling to reach out to people who are not his base. Trump lost because he's incapable of conceiving a scenario where he loses. His ego can't accept that possibility.