I don't fault your rationale; I've been to a couple sad zoos. They definitely exist and should be shut down, and some animals will just never do well in captivity. There are still specific animals I think about years later and I hope they are in better places now.
But I just did a private tour of a really great zoo's operations, and I work wildlife rehab where we need to keep animals in captivity for months many times, and some mind it a lot less that others, and some will come back to visit after being released. Animals face a lot of danger and scarcity of resources in the wild, and in captivity, those things are no longer problems. We often picture animals having these wonderful lives of peace and freedom, but we forget about predation, going hungry for days, either not having or constantly having to defend shelter, and how catastrophic even minor injuries or just getting old can be.
There are mandated standards for shelter, animals get individual care plans, giving them the best of food and medicine, they get protection from extreme weather, they often get to choose mates and get to raise their young in much safer and less stressful conditions, and when they get old or lose teeth, etc they still get regular meals, shelter, and nicely heated or cooled places to rest.
Are they captive? Yes. But well-run places aren't miserable for many animals. Maybe at worst like an all-inclusive resort where they tell you not to leave because outside the resort area it gets rough fast or house arrest when you're a millionaire. Zoo animals inspire a lot of people to get involved with conservation or animal care. At my place, we do let the animals go when they are ready. Most of my coworkers seem to think seeing them go free is the best part. Honestly, I worry about all the animals I release. I saw what got them nearly killed to begin with, and I'm sending them back into that world where most things will want them dead, and there are so many human-based hazards they don't understand. Staying with us would likely at least double all their lifespans. They lose a ton of perks when they leave out care. But my job is to make sure they get fixed up and back to nature. I debate whether I'd rather explore more medical opportunities or to see into animal education, since those animals are unreleasable. Either way, I'm here helping them because of all the amazement I got from nice zoos and aquariums.