Tom Robinson is a decent man who is capable of sympathy for Mayella Ewell, who he knows is lonely and isolated. She is also likely being abused by her father, Bob Ewell. However, in the segregated South of Jim Crow days, a black man could not express this kind of sympathy for a white woman. In the racial hierarchy that was enforced at that time, blacks were considered to be always inferior to whites. Therefore, black people could not express sympathy for a white person. Such a declaration would upend the racial hierarchy and imply that black people were superior or equal to whites, and that expression was something whites could not accept.
Therefore, while Tom Robinson's expression of sympathy comes from the goodness of his heart, it is a mistake for him to have said such a thing in court. His words imply his own equality with whites, and that makes the whites on the jury uncomfortable and unsympathetic to him.