This is a great question. There are a few important reasons why Atticus believes he needs to defend Tom Robinson, even if it is not a popular thing to do.
First, Atticus believes that Tom is innocent. In fact, in the trial scene, he cogently lays out the evidence for Tom's innocence. He persuades the reader for certain, even if the racially charged jury disagrees.
Second, Atticus is a man who stands for justice. So, he needs to do what he believes is right. In one instance, he even stands before a mob of people to defend Tom Robinson.
Third, in a conversation with Scout, he states that he has to defend Tom Robinson, because his integrity is on the line. He explains that if he does not defend him, then he would not be able to tell Scout and Jem to do what is right, because he would not be doing what is right. Here is the text:
“If you shouldn’t be defendin‘ him, then why are you doin’ it?”
“For a number of reasons,” said Atticus. “The main one is, if I didn’t I couldn’t hold up my head in town, I couldn’t represent this county in the legislature, I couldn’t even tell you or Jem not to do something again.”
“You mean if you didn’t defend that man, Jem and me wouldn’t have to mind you any more?”
“That’s about right.” “Why?”
“Because I could never ask you to mind me again. Scout, simply by the nature of the work, every lawyer gets at least one case in his lifetime that affects him personally. This one’s mine, I guess. 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. Try fighting with your head for a change... it’s a good one, even if it does resist learning.”