Atticus Finch is, above all, a man of integrity. He strives to do what he knows is right now matter what the circumstances. In this case, Atticus knows that Tom Robinson deserves a fair trial and that he is the only lawyer in the area who can even come close to making sure he has one. It would be much easier for Atticus to refuse the case. He doesn't have to take it, and he realizes that his neighbors will likely turn hostile toward him if he does. But he allows his conscience (which is well-formed and well-trained) to guide his actions, and he takes Tom's case.
Atticus also understands that if he does not abide by his own conscience and stand up for what is right, then he has no business asking his children to do so. As a father, he has the responsibility to model integrity for Scout and Jim as well as demand it from them. If he fails in his own decision making, his children will see that. Atticus will come across as a hypocrite who orders others to do what he will not, i.e., the right thing.
Therefore, Atticus accepts Tom's case and determines that he will do his best to prove Tom's innocence and to defend Tom in every possible way. He even sits outside the jail one night as a first and last line of defense against the lynch mob. He builds a solid case for Tom. He actually proves the Ewells are lying. Yet when the jury is swayed by their own prejudice and declares Tom guilty anyway, Atticus keeps working on an appeal. He does not stop trying, and he does not stop encouraging Tom no matter what obstacles stand in his way.