What is the history of seeing exotic animals as a public attraction or form of entertainment? How did these "zoos" function and how were wild animals collected and kept alive?
The earliest forms of keeping exotic animals for viewing originates in the practice of a "royal menagerie", a sort of private collection of exotic animals by a ruler. The earliest menagerie that we've found comes from Hierakonpolis, in ancient Egypt, in 3500 BC. Archaeological excavation produced burials of over 100 animals, including dogs, hippos, hartebeests, cows, elephants, baboons and wildcats. The practice likely continued from there.
Why were the animals collected? It most likely was not for public viewing, but for personal reasons, to express the power of the ruler over nature. We have no information about the use of these ancient menageries in terms of public access, but the practice of the royal menagerie continued and spread to other cultures, with the Assyrians and Babylonians participating.
As for how the animals were collected, the were obtained on expeditions. Hatshepsut's famous expedition to the foreign, exotic land of Punt (probably Ethiopia/Somalia/Yemen) is recorded in her mortuary temple, with reliefs and a text describing the things brought back from that fabled wealthy land:
... Loading of ships to a very large extent with precious goods from the land of Punt, all kinds of good herbs of the God's Land, and large quantities of the resin of myrrh, of fresh myrrh trees, of ebony and pure ivory, of green gold from Amu, of f tjSps-wood and hsyt-wood, of resin, incense and galena, of baboons, vervet monkeys, and greyhounds, of hides of Upper Egyptian panthers and of laborers and their children. Never was anything like that brought to any king.
translation by Mark Nederhof (PDF Warning)
So the animals were usually obtained by trade with neighboring people groups or in expeditions. Even military expeditions would often catch animals.
Once they were caught, they were fed and sheltered. Several of the Hierakonpolis animals had suffered fractures perhaps from violent blows (according to Van Neer et al 2015), which were healed, something that could not have happened in the wild. One of the elephants was discovered to have been eating acacia twigs, as well as a wide variety of both wild and cultivated plants, which suggests it was fed on purpose by people.
According to Patrick, Patricia G., and Sue Dale Tunnicliffe. "A History of Animal Collections." Zoo Talk. Springer Netherlands, 2013. 5-17, most publications date "true zoo management" to slightly later in Egyptian history, around 2900-2200 BC, and the likely readons for keeping the animals was for leisure, nobility, and even hunting purposes. Animals also became a political currency, as the gift of an exotic animal could cement a political alliance or as part of tribute.
Stuff I used to write this (besides what has already been cited):
Van Neer, W., Udrescu, M., Linseele, V., De Cupere, B. and Friedman, R. (2015), Traumatism in the Wild Animals Kept and Offered at Predynastic Hierakonpolis, Upper Egypt. Int. J. Osteoarchaeol
Herodotus writes about seeing a giant Indian ant (whatever that means) kept at the court of the Persian King. Apparently they're really good at eating camels and digging up gold. Here's the passage.
No body believes it was a giant ant. Different people have different small furry ideas for what this is. A kind of marmot is popular. Some people are doubtful enough to suspect Herodotus never traveled in the East at all.
I don't know if that counts as a zoo - a single pet ant. It is probably the earliest in the Greek tradition.