Many of these workers are victims in their own right, susceptible not only to exploitation and physical injury — as is true of so many people in low-status occupations — but also to another, less familiar set of hazards, owing to the unpalatable nature of the jobs they do. In their classic book, “The Hidden Injuries of Class,” the sociologists Richard Sennett and Jonathan Cobb called for shifting the focus of class analysis away from material conditions to “the moral burdens and the emotional hardships” that workers bear. For dirty workers, these burdens include stigma, self-reproach, corroded dignity and shattered self-esteem. In some cases, they include “moral injury,” a term that military psychologists have used to describe the suffering that some soldiers endure after they carry out orders that transgress the values at the core of their identity.

“When a man — a good man, or woman — goes into prison, a little bit of your goodness wears off,” a former corrections officer named Bill Curtis told me. “You became jaded. You become more callous.”

The moral slide Mr. Curtis described may be particularly unsettling for those who are well intentioned, including the legion of psychiatric aides who work in jails and prisons, which in recent years have effectively become America’s largest mental health institutions. As I have reported elsewhere, mental health staff routinely violate medical ethics by standing by while incarcerated people with mental illness are mistreated and abused. For example, in the months after Mr. Rainey’s death, Ms. Krzykowski lost her appetite. Her hair fell out. She struggled with guilt and shame and was eventually diagnosed with post-traumatic stress disorder.

Though more difficult to quantify, the moral and emotional wounds that many dirty workers experience can be as debilitating as material disadvantage, shaping people’s sense of self-worth, their place in the social order and their capacity to hold on to their dignity and pride. The result is a form of moral inequality that mirrors the economic kind. Just as the rich and poor have come to inhabit starkly different worlds, an equally stark gap separates the people who perform the most thankless, ethically troubling jobs in America and those who are exempt from these activities. Like so much else in a society that has grown more and more unequal, the burden of dirtying one’s hands — and the benefit of having a clean conscience — are increasingly functions of privilege: of the capacity to distance oneself from the isolated places where dirty work is performed while leaving the sordid details to others.

To be sure, plenty of elite white-collar professionals — Wall Street bankers who sell shady financial products, or software engineers who design hidden spyware — do jobs that are morally suspect. But for white-collar workers who grapple with the ethical consequences of what they do, lavish salaries and bonuses can offset whatever discomfort they may feel. These elites are also less likely to be shamed and stigmatized for what they do than to be envied, lessening the impact of the ethical compromises they may feel they are making.

In my research, I have found that people from marginalized groups are not only more likely to do the dirty work in America, they are also more likely to be faulted for it, singled out as “bad apples” who can be blamed when systemic violence that has long been tolerated comes to light. This is not to say that they are not accountable for their actions. Though charges weren’t brought against them, the prison guards who put Darren Rainey in the shower deserve to be shamed and prosecuted.

But pinning the blame for dirty work solely on the people who carry it out can be a useful way to obscure the power dynamics and the layers of complicity that perpetuate their conduct. In prisons as elsewhere, the conditions that give rise to such work are a product of collective decisions, after all, reflecting our values, the social order we unconsciously mandate and what we are willing to have done in our name.