My son had a snow day and inadvertently our tabby got locked in the spare bedroom. He was in there about 12 hours. My kid was upstairs all day and never even noticed only 2 cats were hanging with him. I got home after 6 tonight and noticed the tabby didn't greet me as usual. I called him and the tuxedo led me to the spare room. When I opened the door, the tabby ran out and the two were excitedly licking each other's heads. She must have been hanging out all day on the other side of the door. It was the sweetest.
I have shut a cat in a closet from time to time. Once when I worked 12 hour shifts my old girl was shut in my closet for almost 14 hours. She had to go while she was in there, and used my laundry basket. I was thankful she didn't use my shoes. And current girls have been shut in my sewing room for an extended period. They chose an out of the way spot to relieve themselves. Now I am uber careful when I shut the door to the sewing room to locate the kitties.
We've had a couple of the outside cats slip into the crawl space when we weren't watching and then get closed up. But, thankfully, we can hear them yowling inside the house so as soon as they decide they've had enough and want out they can just "turn up the volume".