How do you manage compassion for people when they are undeserving? Shmoop's answer: don't bother. To Kill a Mockingbird's answer: a little goodness, a little humility, and a lot of imagination. (No wonder we've never won a Pulitzer.) From the outside, a person may seem vile, stupid, or just plain incomprehensible. But if you can imagine what it's like inside that person's head, you might be surprised by the answers—and compassion—you find. Of course, there's also the danger that the person is just as nasty as you thought, but that's the risk a good person has to be willing to take.
By associating Atticus with both justice and with compassion, To Kill a Mockingbird suggests that the two ideas are not mutually exclusive.
Compassion can sometimes be dangerous: Tom's compassion for Mayella and Atticus's compassion for Ewell gets both of them into trouble.