There are two main reasons why Congress passed the Civil Rights Act of 1964 and the Voting Rights Act of 1965. The first reason was the Civil Rights Movement, most famously led by Martin Luther King, Jr. The second reason was the leadership of President Lyndon B. Johnson and the legacy of President John F. Kennedy.
One reason for the passage of these acts was the fact that President Johnson was a skilled legislative operator and Congress was disposed to want to pass the acts in memory of President Kennedy. When Kennedy was assassinated, Johnson became president. He had been a senator who was known for his ability to get laws passed. It was somewhat easier for him to get these acts passed because members of Congress felt bad about Kennedy's death and were more inclined to pass laws that they felt he would have supported.
Perhaps more importantly, the Civil Rights Movement had created a climate where it was easier to support these laws. Beginning with the Montgomery Bus Boycott in 1955 and 1956, the Civil Rights Movement grew in importance and prominence. It can be said to have peaked with the March on Washington of 1963 in which Dr. King gave his famous "I Have a Dream" speech. The movement helped make many Americans more sympathetic to the idea of civil rights for African Americans. As people came to support the idea of black rights, it became easier for Congress to want to pass laws like the Civil Rights Act and the Voting Rights Act.
Thus, these laws were passed in part because of the Civil Rights Movement and in part because of the skills of President Johnson and the legacy of President Kennedy.