I caught a bat in my house, so I built a glass cage around it and put a name tag on it. A few Minecraft days later, it's no longer in the glass cage. Do animals like this bug out sometimes or did it just despawn on me?
The wiki for Bat indicates they despawn similarly to Squid & Ocelots, both of which I believe I've seen successfully kept as (nametagged) pets…
Mobs 'phasing' into or through blocks when chunks load/unload (where they either suffocate or escape) is a longstanding and ongoing glitch; this is what I'm guessing happened.
WARNING: I have an extemely "grindy" playstyle; YMMV — if this doesn't seem fun to you, mine what you can from it & bin the rest.