Atticus Finch defends Tom Robinson because he sees the injustice in what is happening and believes he can reveal this injustice to others. He feels it is the right thing for him to do. He also uses the appointment to expose stereotypes among races and classes of people.
Atticus knows there is no way Tom can receive a fair trial, and that he isn't going to get a jury of his peers. The extreme prejudice of the entire town does not allow Tom to receive justice, and Atticus believes he can at least bring this to the light of day. He admits he cannot win the trial but must do what is right despite the probable outcome. It is not only because he wants to do what is right, he also wants his children to see him do what is right. Through testimony and the actions of those in court, it is revealed that a person's class may limit him as much as a person's race in certain situations. The Ewells are considered trash by both black and white neighbors, and they are so physically dirty that they are indistinguishable from a black person. In contrast the homes of the Ewell's black neighbors are clean and pleasant.