In relation to people with dementia in nursing homes, my experience of my father being in a care home and then a nursing home was that the level of care was very, very variable, and the knowledge of dementia rubbish. (Examples follow relating to getting out.)
The care home Dad went into didn't specialise in dementia when he went there but later claimed to. The manager was a twerp. A little example relating to patients going where you want them to...she wanted part of the building re-decorated. She didn't listen to staff (or people like me as well) telling her that you have to make the doors you want people go go through easy to find. Nope, she insisted on having the doors to corridors and rooms white with white frames against white walls. Then she was puzzled as to why residents who previously happily went through a hallway from one corridor to another suddenly started going through a fire escape. You know, the door that was easily identifiable as a 'door' not a 'shinier bit of wall'. Duh.
There are lots of ways of stopping residents getting out and away without their feeling locked in. When my grandmother was in an asyslum, they had a simple technique - two handles on the door to the ward. You had to lift one up and push one down at the same time. They didn't have lost patients or patients distressed at being locked in, only slightly baffled ones. You can also put a screen across in front of the door and lots of distractions near it.
And I take a very pragmatic view - in practical terms, there won't be many people who have enough capacity to deal with stuff like that who aren't safe to let out. The ones that fall into both categories should be somewhere special, but they're a minority.
But then my anger really took off over Dad being portrayed as trying to get out when he wasn't. He'd be parked in a conservatory and late afternoon (as he was 'sundowning') he'd start saying "I want to go home now." What he meant was "The function/party is over, where's my transport?"
My advice was to say "But you're booked in for the night. It's all paid for and the chef's expecting you for breakfast. Would you like a cup of tea?" If "it's all paid for" wasn't enough to imprison him, a biscuit as well would do the trick.
But no, if the manager got involved, she'd say he couldn't go home because he had to live there now, but not to worry, I lived round the corner. Except that what she refused to take on was that my mother's name and mine were the same, so she was telling him that his wife lived round the corner, so he'd think either that she'd be expecting him home so he definitely had to go home, or that she'd divorced him. I kept saying "You've got residents whose parents visit. If I was his mother, you wouldn't say "Sunny lives round the corner, would you? You'd say your mother lives round the corner. So my name is Daughter. Tell him his daughter lives nearby."
But she wouldn't. Day after day, she effectively told him his wife had walked out on him. The savvy staff, mostly underpaid frontline staff, referred to it as a hotel. The manager said it was lying. I said it wasn't. Linguistically it's not significant. You don't own the place but you're staying there, they do the grocery shopping, the cooking, the cleaning...and because it's posh, they launder your clothes and polish your shoes.
The point I'm making is that if it's not safe to let someone out, how you keep them there has to vary according to the person, especially if the issue of how much mental capacity they have is a bit difficult. Ironically, in Dad's case, he never knowingly tried to leave the building anyway, even though if he had, he'd have recognised the road and made his way home. Even if you lock the doors, better to keep them there psychologically through warmth.
And if you do have to lock some in, making most of the rest feel they're there by choice at least reduces their distress at being locked in.