SACRAMENTO, Calif. — A federal judge’s objection to what he called the horrific treatment of some mentally ill inmates in California prisons highlights a trend that has been building for decades in the state and across the country: As mental hospitals closed or were scaled back, prisons and county jails have become the de facto housing for many who are mentally ill. California is struggling to deal with more than 33,000 mentally ill inmates, accounting for more than a quarter of the population of 120,000 …