In Harper Lee's To Kill a Mockingbird, there are several places in which Atticus points out the logic and moral necessity to defend Tom Robinson.
Early on in the novel, Atticus explains to his brother Jack one of the most substantial reasons for the logic and morality of defending Robinson. In Chapter 9, Jack and Atticus begin discussing the case. Jack asks "how bad" the case will be, and Atticus replies, "It couldn't be worse" and continues to explain what evidence is being used in the case:
The only thing we've got is a black man's word against the Ewells'. The evidence boils down to you-did--I-didn't. (Ch. 9)
On the one hand, as Atticus further explains, the jury will be very unlikely to acquit Robinson based on that sort of testimonial evidence since it requires the jury to "take Tom Robinson's word against the Ewells'." On the other hand, the usage of only testimonial evidence helps show just how extremely unjust the trial is. A crime cannot be tried simply based on what one person says over another person. There must be concrete evidence proving that a crime was even committed before a crime can legally be tried. As Atticus further points out through his cross-examination of Sheriff Heck Tate during the trial, the court does not even have a doctor's evidence proving that Mayella was taken advantage of that night because a doctor was never called. All of this shows us that Atticus is fully aware that there is not enough evidence in the case to legitimately convict Robinson, yet Atticus also knows Robinson will be convicted regardless, simply due to racial prejudices. Therefore, Atticus knows it is logical and morally correct for him to put his all into defending Robinson.
Another reason why it would make sense for Atticus to defend Robinson is because he knows what Robinson's character is like through things Calpurnia has said about him. As Atticus explains to Scout towards the beginning of Chapter 9, Calpurnia is well-acquainted with the Robinson family since the family is active in Calpurnia's church. According to Atticus, Calpurnia says the Robinsons are "clean-living folks," which is enough for Atticus to be convinced that Robinson is a decent, God-worshiping man who is worthy of being defended.