The reason that Atticus takes on the case of Tom Robinson in Harper Lee's To Kill a Mockingbird is because he was assigned to do so by Judge Taylor.
Atticus is a man of conscience, and had a choice been given to him to defend Tom, a black man in the deep South accused of raping a white woman, I believe Atticus still would have taken the case, believing in the rights guaranteed by the Constitution to all men and women, regardless of color—which is really at the bottom of the outcome of this case. The problem here is not of a crime, but about race—the accusation is that Tom raped Mayella, but the truth is that Mayella tried to get Tom to kiss her, and her father found out—he saw her: beat her for it, and accused Tom of a crime he did not commit.
In Chapter Sixteen, as the youngsters mill around in the courthouse waiting to take their seats, Scout overhears some men talking.
When [the members of the Idlers' Club] spoke, their voices sounded casually important. The conversation was about my father.
"...thinks he knows what he's doing," one said.
"Oh-h now, I wouldn't say that," said another. "Atticus Finch's a deep reader, a mighty deep reader."
"He reads all right, that's all he does." The club snickered.
"Lemme tell you somethin' now, Billy," a third said, "you know the court appointed him to defend this n***er."
"Yeah, but Atticus aims to defend him. That's what I don't like about it."
This was news that put a different light on things: Atticus had to, whether he wanted to or not.
Scout is puzzled because this information would have helped her defend herself against the criticisms of other children and some adults (Mrs. Dubose, for example) because Atticus was defending a black man. She doesn't understand that Atticus didn't tell them because he did not feel compelled to defend Tom at the court's request, but agreed to do so because it was the ethical thing to do. Atticus is, more than anything, a moral man who wants always to set a strong example for his children and never let them down in by being hypocritical.
The community criticizes Atticus for just this reason: he is not only defending Tom, but he's doing it as he would for any white man. Many of the townspeople are not able to handle this—that a black man would be treated as well as a white man. Atticus makes it clear from the time the men come to lynch Tom at the jail that he means to do things in a fair and decent way.
In Chapter Twenty-two, Miss Maudie explains it to all the children:
Stop eating and start thinking, Jem. Did it ever strike you that Judge Taylor naming Atticus to defend that boy was no accident? That Judge Taylor might have had his reasons for naming him?
In this story, Atticus is directly asked by Judge Taylor to take the case. Miss Maudie infers that the Judge knew that while Tom might not be found innocent under Atticus' "care," he would receive a fair trial, which speaks to the character of the judge as well.