Sometimes your Allied CS will discover a CS that is allied with the AI you are at war with. This means that you (through your ally) have made that discovery. Since it was already an Ally with your enemy, it declared war upon being discovered.
I was sceptical about this when I read it, but didn't respond because I was unsure and didn't have any evidence. However, that's not how it works.
I like your idea about getting contacts through an ally, but the only way you can meet other players through an allied City State is through the bit of the map that gets lit up between allies. You'll discover them yourself through the fog of war that gets removed.
And for a City State to declare on you no type of contact through another City State is needed at all. I was lucky (or unlucky) to get the same situation again in a game, and this time I made a save and some screenshots. I'll show what happened.
Isabella declared on me on turn 24. I knew she was allied with Kuala Lumpur, but when she declared on me, she turned out to have an other ally, Kathmandu. She had found El Dorado first and had decided to let her money roll. Both CS's declared. I had not yet met kathmandu and was not yet allied with any CS that could have made this contact for me.
This was my explored world - playing as Mongolia:
You can see 3 CS's I had met: Kuala Lumpur (yellow), Belgrade (green) and Rio de Janeiro (hazy yellow). Also you can see a bit or Spain and Russia north of me.
If I would have contacted Spain just before she declared, I would have seen these parties listed as our mutual contacts:
Kathmandu is not mentioned. Although I'm still friendly with Spain, contacts do not get shared in Civ 5, you have to discover them yourself.
Unless war happens. Because when Isabella declares, I all of a sudden get to know about Kathmandu:
The only plausible explanation for this that I could accept is that Spain has shared knowledge of me with Kathmandu, and Kathmandu follows Spain out of loyalty.
The only problems I would be left with then are:
* I can't think of any historical example of two parties that declare war without knowing each other;
* It's odd in game to be at war with a party you don't even get to see on the map;
* Allied CS's on other occasions sometimes follow completely their own agenda, like declaring a permanent war against a civ you have a declaration of friendship with. They're not bound to follow your diplomatic stance.
I find it good for the game that a CS you are allied with automatically declares war on any civ you yourself are at war with, absolutely agree and it should be like this, but there's no need to stretch this beyond civs they know.
I'm a little bit surprised that a lot of people seem to think it's okay, but I can't do much about that. You could indeed hold the opinion that this is a feature, not a bug, but that's something you could say about many bugs.