So it was started after the Civil war by Democrats against blacks AND whites who were Republican. It sounds like it's initial goal was political and not really just hating black people. Did it evolve into just hating black people? Were they always against Republicans?
Well, here's the thing.
What you're talking about took place during the Reconstruction Era. Reconstruction tried to bring the Southern states back into the Union and reform the area from slavery and discrimination of blacks. During that time, ex-Confederates were not allowed to vote and the Southern states did not have formal membership in the Senate. This meant that the whites in power in the South had no formal method of maintaining segregation.
Also, the Southern states were occupied by Federal troops to ensure laws against slavery and discrimination were being enforced. Federal troops protected blacks from the Southerners who tried to continue the racism of the area.
The third part to Southern anger in the Reconstruction period was at the "carpetbaggers," who were wealthy Northerners who bought up land and property of Southerners who went bankrupt during or because of the war. They preyed on the financial destitute of Southerners for their own profit and gain.
So because white Southerners 1) didn't have any representation in government, 2) were preyed upon by financial predators, 3) were threatened by Federal troops, 4) saw their place in the Southern class system being overturned by blacks who had gained their freedom, they decided to form a group that would look out for their interests: the KKK.
So, originally, the KKK wasn't even a terrorist organization - they were more like a white Southern "street gang" in that they formed together in order to look out for their mutual interests against threats. This is similar to, say, all the Italians of New York City forming a mafia for mutual protection, and all the Irish forming a gang to protect their own people.
This continued until the Compromise of 1877, in which Republican Presidential candidate Rutherford B. Hayes agreed to end Reconstruction, end Republican control of Southern states, and pull Federal troops out of the South in order to gain the Presidency. After this, ex-Confederates regained the right to vote and most Southern voters registered as Democrats so they could vote against the Republicans who fought them and reigned over them during Reconstruction. This became the "Solid South" and allowed them to create Jim Crow laws and was the era of Redemption in which Southern racists used laws to discriminate and segregate blacks.
Because racists whites in the South were able to vote laws to oppress blacks "legally," the KKK moved from being a "gang" committing violence and more as a social club. Basically, government-supported racism was the culture of the time, and the KKK was so powerful with voters that many politicians of the time had to join up just to get the KKK's endorsement for voter support, much like how politicians seek the endorsements of the NAACP, AARP, ACLU and the endorsements of other organizations for voter support.
The KKK lost support during the Civil Rights Era of the '50's, 60's, and '70's, as more people lobbied to end Jim Crow laws and write laws that better guaranteed rights of blacks and other minorities.
It was during this period that the Democratic Party started to split. There were northern Democrats who supported Civil Rights, such as the Kennedys, and the "Solid South," also known as "Dixiecrats," who opposed it, one of which was Strom Thurmond. Although they belonged to the same party, the regional differences grew and grew as time went on.
During the '70's, Richard Nixon (called "Tricky Dick" for a reason) took advantage of this and used "the Southern Strategy" to come up with policies that favored "states' rights" in order to get the vote of Southerners despite being a Republican. Since then, the "Solid South" has moved over to the Republican Party as a party for Southern conservatives to belong to. There is no better example of this as Strom Thurmond joining the Republican Party during that time.
I know you asked about the KKK and I included a few more things, but I think that's a pretty good summary of not just the KKK but also the regional politics and party involvement. This also shows why Democrats in the South are much more socially conservative than Democrats elsewhere while supporting more government involvement, and why the Republican Party moved from being mostly a party of pro-business interests to also being extremely socially conservative.