Boo and Mayella may well have been the two loneliest people in Maycomb, but Mayella took even more extreme measures than Boo to make friends. Whether Boo knew about his reputation as Maycomb's leading ghoul, his reclusive position in his house was at least voluntary; he could have chosen to venture out into the neighborhood had he wanted. He would have been welcomed by Atticus and Miss Maudie, and the children would probably have learned to accept him--as Scout did in the final chapter. Mayella, however, had little choice in the matter. She was stuck at her home on the edge of town, responsible for taking care of her younger siblings. She had no friends of her own, no money, and no one visited her despised family. Few people passed her way accept for Tom Robinson--a married African-American man. Although the Ewells apparently despised their Negro neighbors, Tom appeared to be her only choice for companionship. So, when he entered her home, she took a chance on one of the least likely persons imaginable to be interested in her advances.
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.