The book is unlike the film, because we don't actually see Judge Taylor approach Atticus and ask him to take the case. Instead, the first mention of him accepting the case is when Scout hears kids at school saying terrible things about her father. She comes home from school and questions Atticus, who responds:
Atticus sighed. “I’m simply defending a Negro—his name’s Tom Robinson. He lives in that little settlement beyond the town dump. He’s a member of Calpurnia’s church, and Cal knows his family well. She says they’re clean-living folks. Scout, you aren’t old enough to understand some things yet, but there’s been some high talk around town to the effect that I shouldn’t do much about defending this man. It’s a peculiar case—it won’t come to trial until summer session. John Taylor was kind enough to give us a postponement…”
Later, in Chapter 16, we learn the important detail that Atticus was assigned the case; he did not volunteer. This illustrates the sacrifice that Atticus made by truly defending Tom Robinson. He didn't have to; he had a perfect opportunity to blow it off and keep the town happy. But Judge Taylor assigned him the case specifically because he knew that Atticus would do the right thing. In this chapter, we read:
“Lemme tell you somethin‘ now, Billy,” a third said, “you know the court appointed him to defend this nigger.”
“Yeah, but Atticus aims to defend him. That’s what I don’t like about it.”
Atticus shows what a true defender of the law he is by truly defending Tom Robinson.