@Barbara S.
I've read your post and responses and emphasize with you. While you are clearly frustrated and understandably so, your situation is not as cut and dry of that of an ordinary landlord.
This is where you need to first be a caregiver, then landlord. Rather than focus on getting a lawyer, try finding some compassionate person, maybe from a nearby senior center or such and ask them to help you sit and talk with your tenant. Or see if you can find someone in his circle that he values and respect to serve the same role.
As someone in the senior homecare industry I can't tell you how often I've witnessed the effects of aging, the lack of control over one's inability to function independently, the fears whether realized or not that this population live with. Getting old is not for the faint of heart, even harder for those of us who have to interact with them.
During your mediation, find out if there is a work around to the keys, such as perhaps a coded door if this would work better for him. Or make him a gift of a key ring that would hold some sentimental value to him and then color code each of the 3 keys he needs for entry to the apartment and place on said keyring.
No amount of stronghold enforcement will work with him. You will have to go above and beyond to get through to him, by dialogue, compassion and understanding. You already know he fears being locked in or out, hence he leaves the door open.
As for the other issues, look at how you can rectify these as well. You mentioned his bathroom hasn't been cleaned in ages. What can you do to address this? He said the repair bill is too high, so he is at least aware that he should be responsible, this is a start.
While you do the above, see how best you can get a caseworker assigned to him, citing fear for his wellbeing, endangerment and safety of others, and see if you can help him to transition hopefully to his next place of abode.
It's not easy I know, I'm preaching to the choir.