I honestly don’t understand why cities moved to get rid of them.
Some of it was economic. That’s why you have things like zoning— all houses on a block have similar requirements, similar usages. You don’t have a grocery store, a 2/1, a 5/3, and two garage apartments all next to each other. My block was built up in the 1920’s— and that’s exactly what we’ve got. (The grocery store has since been transformed into a sfh.) So ultimately, rich people didn’t want to live next to poor people.
That’s also why you have things like number-of-people-per-bedroom, or number-of-sf-per-person restrictions in rentals. We all know the stories of the turn-of-the-century families who lived, 10 in a 1-bedroom house. Once upon a time, I thought I was renting a 1/1 to a mom, dad, and infant. OK, it would be a bit tight, but it was cool. I realized when they moved in, however, that it was actually mom, dad, infant, his two kids from another relationship, and her other kid from another relationship. I was okay with putting in 3 people in a 400 sf house… but I wasn’t going to put a family of 6 in 400 sf. I made them leave, because they had lied on their application. But 100+ years ago, that was perfectly normal… you did what you needed to do in order to make ends meet.
So, back in the day, they said, “We can’t have overcrowding due to public health concerns! We don’t want disease to spread!” But, oops, somehow, it mostly seemed to apply as a way to clear out immigrant neighborhoods, rather than university dorms, prisons, military barracks, owner-occupied residences with big families…
Same thing for fire safety concerns.
Capsule hotels used to be very common for workers and traveling salesmen and [whoever else needing cheap lodging on a tight budget. Or renting the same hotel room in 8-hour shifts to shift workers. Those hotels still exist in other parts of the world, but it looks like this—
and we decide, “Nope, that’s just not healthy” and ban it. It might not be ideal---- but when it’s the difference between homelessness and shelter— I remember driving through downtown Houston at 3 in the morning, and seeing blocks and blocks of people neatly lined up sleeping on the sidewalk under bright lights.

It was so unexpected, it took me a while before I understood what I was seeing.
There were certainly dangers. There was the
arsonist who set fire to two stairwells at the Seattle Ozark Hotel, which was a Single Room Occupancy (SRO) hotel. 20 people died in that fire. They said, “Oh, you need fire sprinklers!” and came down on buildings that didn’t have good sprinkler systems and fire escapes in place— which was a good idea. But then the Seventh Avenue Hotel burned about a year later, and 12 more people died… and more restrictions were added.