If we take President Johnson’s own words seriously, we must conclude that he supported the Civil Rights Act of 1964 because he genuinely believed that it was the right thing to do. He may have been motivated in part by the desire for political gain or the desire to have something great as part of his legacy. However, it is not completely clear that pushing this law would have seemed expedient at the time.
In his speech in front of a joint session of Congress on March 15, 1965 (obviously, this is after the Civil Rights Act of 1964 was passed, but before the passage of the Voting Rights Act of 1965), Johnson makes clear that he sees this question in moral terms. He argues that the country must do what is right. As he says,
The issue of equal rights for American Negroes is such an issue (one that is about basic American values). And should we defeat every enemy, should we double our wealth and conquer the stars, and still be unequal to this issue, then we will have failed as a people and as a nation.
If Johnson says this about black voting rights, he would presumably also have felt it with regards to the Civil Rights Act of 1964.