We study bias in judicial authorities’ efforts to rehabilitate and reintegrate immigrant offenders into society. Our empirical strategy leverages a distinctive feature of the German criminal code: the optional application of rehabilitative juvenile criminal law or punitive general criminal law for eighteen- to twenty-year-old offenders, based on a subjective assessment of offenders’ psychological ‘maturity’ by judges. Drawing on complete records of 792,000 court hearings between 2009 and 2018, we show that immigrant offenders are about ten percentage points less likely to be sentenced under juvenile law compared to natives convicted for the same crime. The immigrant–native gap in rehabilitative justice correlates with anti-immigrant sentiment across space and has spiked in recent years, suggesting a link between the salience of group-based identities and judicial decision-making. Our findings raise concerns about equal legal treatment and highlight that biases in the application of rehabilitative justice may contribute to higher recidivism rates among immigrant offenders.