Otherwise, you're right. Historic tunings often tried to optimize for a certain base scale (often times C major), while leaving behind a really bad sounding tuning at the other side of the circle of fifths ( https://en.wikipedia.org/wiki/Wolf_interval ).
Modern pianos are usually equal tempered, which is the strategy of leaving every scale equally bad off - but on the other hand being able to play in all keys without sounding too bad (The famous "well-tempered piano" is referring to this historic change in tuning strategies with small pieces written in all different kinds of keys, all of which would have sounded weird before).
The more I learned about tuning, the more complex, beautiful and sad this topic became for me: http://blogs.scientificamerican.com/roots-of-unity/the-sadde...
It's fascinating and even a little philosophical that we can get so close to perfection with the 12 step tuning - but never, ever completely attain it.
By the way - That's part of the reason why choirs and orchestras often sound so good: As most other non-fixed-string instruments are able to do a slight adjustment in pitch, they can actually play perfect intervals in any chord, dynamically adjusting to any scale.
Wind instruments are necessarily tuned to a specific key, due to the nature of the harmonic series. But most talented wind instrumentalists are capable of modifying pitch to be in tune in any key or chord.
Down the rabbit hole, read on at your own peril:
Even string instruments are tuned to a key, to a certain extent, due to the use of harmonics. It is possible to fine tune the pitch of a harmonic by shortening the string as usual, but it is exceedingly difficult, since shortening the string changes the position of the nodes (the spots on the string that must be touched in order to produce harmonics).
Also, pianos rely on resonation. I would not be surprised that the sound board and resonant cavity is designed to favour certain tones. I'm not certain about this though.