I don't think they used to have them as pets before there could be fish tanks, because you can't see them, so what's the point? (but I could be wrong, people are weird).
Also, glass was very expensive for a long time, and was used for drinking water or wine, or seeing better, I guess eventually some rich dude thought "I could put a fish in here", it probably was a very weird idea at the time, but I have no clue when nor where did that happen
It’s not a perfect match for your question. But I provided an answer to a question about Roman fish tanks here. The short answer is the Romans definitely kept fish in ponds and artificial tanks , collectively known as piscinae. I can’t answer conclusively when people started keeping fish as pets, but it’s been at least 2000 years.