How does this happen?

I think it's the outcome of Republican political tactics since Nixon (the Southern Strategy and alliance with the religious right) and the network of direct mail, talk radio & TV (notably Fox), periodicals and internet propaganda outlets that accompanied the rise of movement conservatism and stoked the culture wars. In short, the politics of resentment.

Their efforts have been quite successful, cementing social conservatives to the GOP and producing in a signifiant swath of the electorate the conviction that liberals are intent on robbing real Americans of their hard-earned dollars and giving them away to black people and other undeserving minorities, who then get to attend elite universities like Harvard and Princeton and become president and First Lady of the United States.

At the same time, during a period of wage stagnation, the Democratic Party became less identified with labor and the working class and more oriented toward professional cosmopolitans.