Most of the states in the deep south, from post civil war until approximately the early 1960s had majority black populations. Once reconstruction ended, in order to maintain/get back political power, the whites enacted various measures to keep most blacks from voting, and thus voting the whites out of office. For generations the deep south voted democratic, not so much that it was the party that represented most of their political beliefs, but because it was the party that enabled the whites to maintain political power and control.
Then from around the turn of the century and continuing until around the early 60s, the great black migration from the south to the north and west took place. As a result, the demographics of the states of the deep south changed as the white population became the majority. That significant fact, coupled with the enactment of civil rights legislation guaranteeing the rights of blacks to vote, caused a gradual shift in a large proportion of the white electorate to the Republican party. Conservative social issues that had been complete non-issues until the 1970s and 1980s (most notably the abortion issue) were taken up by the Republican party as a means for swaying former democratic voters in the deep south to change parties.
However, in order to hold onto the gains that the Republican party made with a majority of whites in the deep south, it also took positions counter to its original role as the party of emanicipation, one example being by vigorously fighting against affirmative action. As a result, blacks deserted the Republican party. Nevertheless, the Republican party became the dominant party in the South.