In Chapter 9 of To Kill a Mockingbird, the reader first learns of Atticus's having accepted the role of state-appointed defense attorney for Tom Robinson, who has been charged with allegedly raping Mayella Ewell, after Scout engages in a fight with Cecil Jacobs who accuses Atticus of being a "n***r lover."
Atticus explains to his daughter that he was court appointed to this task, adding,
"...every lawyer gets at least one case in his lifetime that affects him personally."
Later, Scout has a fight with her cousin Francis, who also accuses her father just as Cecil has done, Uncle Jack intervenes. Scout begs him not to tell Atticus, and he keeps the incident secret. However, he asks Atticus about having taken the case; Atticus says that he could not face his children without having done so because he does not want them to grow up with "Maycomb's usual disease."
We are not told specifically when Atticus agrees to take the case, but as the previous answer makes clear, we first learn of it in Chapter 9. This is the first intimation of the difficult times that lie ahead for the Finch family over the case. Atticus counsels Scout to exercise restraint, because the case is going to cause a lot of negative talk and he knows that she is fiery and liable to lash out at the first provocation. He knows there will be plenty of provocation in the days ahead, and he wants her to meet it with dignity.
You might hear some ugly talk about it at school, but do one thing for me if you will: you just hold your head high and keep those fists down. No matter what anybody says to you, don’t you let ‘em get your goat.
This is perhaps the first major life lesson that Scout has to learn. Of course, she doesn't learn it all at once, and it's not long before she's fighting her aggravating cousin Francis over the same subject.
The introduction of Tom Robinson's case in this manner - through Atticus's explanation to the young Scout - is quite appropriate, as of course the whole novel is seen from the young Scout's perspective, with some seasoned remarks from the older Scout in retrospect. The circumstances of the case are not immediately made clear, as Atticus tries to distill it into terms that a child could understand. At this stage, all we really know is that it's something that's going to spell trouble for the Finch family.
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.