David Skarbek is a political scientist who studies prison gangs. In a *fascinating* interview with *Asterisk*, he describes the forces that led to the rise of race-segregated prison gangs, from virtually nonexistent for 100 years to ubiquitous:
https://asteriskmag.com/issues/08/why-we-have-prison-gangs
It boils down to this: in small prisons, it's possible to enforce a social code among prisoners to maintain order. Each prisoner can track the trustworthiness of others and of the safety risks they pose.
34/