Though the novel demands that we view Mayella from a child's relatively naive position, Scout is attuned to her loneliness in ways that the adults around her are not, though Scout cannot understand the structural impediments to Mayella's happiness.
The Ewells are condemned as "poor white trash." Their only recourse for feeling better about themselves is to take refuge in their whiteness and hate black people. This animus is turned onto Tom, one of the few people to come near them.
It is significant that Mayella's mother is dead. Because she is the eldest of the family, she has usurped the role of mother to her younger siblings and, possibly, that of "wife" to her father. One could read the possibility of incest into Mayella's relationship with her father, due to his venomous jealousy toward his daughter's friendship with Tom.
Mayella, like most Southern white women at the time, was regarded as the possession of a white man—in this case, her father. The sense of entitlement that Southern white men expressed in their relations to white women expressly forbade any intermingling with black men. Tom represents fears, both sexual and political, that were used to justify segregation.
Mayella, however, is unable to have friendships with whites, due to her class, and is forbidden from relating with blacks, due to her race, and is especially forbidden to have any relationship with black men due to the parameters set by her race and gender. When the prosecutor registers surprise at Tom's comment that he felt sorry for Mayella, it is because he finds it impossible to believe that a black person could have any reason to feel sorry for a white one. As a white man, he does not recognize the ways in which he and other white men restrict the freedoms of white women, and, as a man with an education and a middle-class status, he does not recognize the way in which Mayella's poverty isolates her.