Prior to the New Deal, black voters were almost uniformly Republican. The Democratic Party itself was very split on the issue of Civil Rights, from being uniformly against civil rights laws in the late 1800s to dividing into, effectively, two factions: the pro-civil rights Democrats in the north who could be reasonably described in modern terms as "liberals," and the anti-civil rights Democrats (Dixiecrats) in the south who would be described in modern terms as "conservatives." Similarly, the Republicans were almost uniformly liberal on civil rights in the north, and did not really exist in the south until the early 20th Century. The Republicans who emerged in the south were, generally, even more conservative than the Democrats in the south.
So by the 1960s, you had the Democrats who were fairly uniformly liberal on economic issues throughout the nation, but split between liberals in the north and conservatives in the south on civil rights, and Republicans who were fairly uniformly conservative on economic issues throughout the nation but on civil rights were split between liberals in the north who were very similar to northern Democrats and conservatives in the south who were very conservative on civil rights. So while on economics, the dividing line between liberal and conservative was party, on civil rights the dividing line was regional: the north was liberal and the south was conservative.
Like most poor Americans, the black population moved heavily towards the Democrats during the New Deal, but they weren't uniformly Democratic (many black voters backed Eisenhower in the 1950s, as he was a relatively liberal northern Republican on civil rights issues). In 1960, both the Democratic (Kennedy) and Republican (Nixon) candidates for president were from outside the south, and while strongly divided on economic and military issues, they were fairly well in line on civil rights questions.
After Kennedy won, and was assassinated, his successor, Lyndon Johnson, pushed hard for civil rights legislation. Though he was from the South, LBJ had drifted to a liberal position on civil rights in the 1950s -- arguably because he realized no Democrat from Texas was going to get anywhere in the national party if he was out of step with the majority of the country on civil rights. Of the four blocks of votes -- liberal Democrats, liberal Republicans, conservative Democrats, and conservative Republicans -- the conservative Democrats, having held all but a handful of seats from their southern states for decades due to a lack of competition, were the most senior and powerful block in the Congress. However, the combined Republicans and Democrats who were liberals on civil rights outnumbered the conservative southerners. LBJ was able to maneuver the legislation through.
In the end, as expected, it was the regional, not partisan, factors that determined the votes:
Northern Democrats voted 95% in favor of the Civil Rights Act. (190 of 200)
Northern Republicans voted 85% in favor of the Civil Rights Act. (165 of 194)
Southern Democrats voted 7% in favor of the Civil Rights Act. (8 of 115)
Southern Republicans voted 0% in favor of the Civil Rights Act. (0 of 11)
In the 1964 election, black voters shifted heavily to Johnson because of his part in pushing the law and because his Republican opponent, Barry Goldwater, loudly opposed it. By 1968, the Republicans began making gains in the South by running candidates that were more conservative on civil rights issues than Democratic incumbents. Over time, as black voters stuck with the Democrats because of the combined influence of the New Deal and the Civil Rights Act, the Democratic Party as a whole moved in line with the Northern Democratic position from 1964, while the Republican Party as a whole sort of averaged the difference between it's two factions' positions in 1964. This led to major gains for the Democrats amongst black voters and liberals in the north, and for Republicans amongst white conservatives in the south. It was a major realigning event in American political history.
So while many African Americans today are more socially conservative than the Democratic Party as a whole, they continue to vote Democratic en masse because on economics they've been with the Democrats since the New Deal, and since the mid-1960s the Democratic Party has been the loudest champion of civil rights. It's not that hard to understand.