Locked in? Locked out? Trouble manipulating door locks is common in the later part of dementia and can cause your loved one to grow angry or frightened. Some ideas:
Keep a spare key where you can easily find it but the person with dementia can't, such as on a ledge above the door or on a hook inside a cabinet.
Cover the lock with duct tape, if possible.
Consider removing indoor door locks altogether. A locksmith can easily convert them.
Consider going so far as to remove doors from important rooms and use curtains instead. You may lose a little of your own privacy but gain some peace of mind about your loved one.
Do these things when your loved one isn't watching, and the change may not even be noticed. If it is, you can explain that it's "being fixed."