They don't. Southerners do. Racist Southerners. And, taking their cue even in Canada now, racists throughout America do.
I've known plenty of Republicans, and I've not seen a Confederate flag in my entire life anywhere but on the screen and in books. Not even a bumper sticker, nothing. Frig, I've even seen the flag of the Isle of Man of all places at a house, but never a Confederate one in the flesh. I've seen and lived near actual White Southerners as well - a family used to live around the block when I was a kid even. No Confederate flags though.
Republicans have always been racist, you know, like people tend to be, only most don't go around lynching people. Look at St Jesus White Savior of Slaves Lincoln's own words. This wasn't some secret side, this was typical of the times.
Segregation, mind you, wasn't restricted to the South, it was throughout the US before, nay, Canada too, oh, and Mexico, even Puerto Rico, where my mother told me of how her family was a member of un "Asociacion" ("Association" in English) which was only for Whites and went to chaparoned balls again, also Whites only. Never mind that it was rather apparent that my grandmother had a degree of Taino features as do my aunt and uncles (albeit only slightly with them. My ma looks more like my grandfather round the eyes), but that stuff was stressed back then, and yet they were nowhere near as racist as folks here.
We moved to an Italian neighborhood in the Bronx when I was 8 - not highly recommended for PRs (as seen on tv!) then. My friends used to say how they were going to become Republicans because they were gonna work Wall Street and wanted to pay taxes. Racist Italian Republicans, not a single Confederate flag anywhere to be seen.
Republicans came about as an abolitionist party, but were also federalists, for big centralized gov't, and favored the gov't backing of business. Sound familiar?
Democrats were more about individualism and State's Rights. Sound familiar?
They have always been more diffused about idealogy than having a central one, thus they've always been more open to change.
As a party they were not pro-slavery per se, they just viewed it as a state issue to be settled at that level, not by the federal goverment. So that's what that rep emerged from.
There was never a party switch, it was only the membership that did. Democrats were open to progress, Republicans were not. Thus those who wanted an ossified monolith flocked to the GOP, because that's conservatism