Did you intentionally work on developing this, or did it come naturally?
I've had the ability to name the key of a song by ear for a few years...probably since my freshman year of undergrad. At that point I had been playing guitar for about 7 years, and had somehow internalized key signature.
For me, it feels very calculated, although I didn't begin doing it intentionally. I essentially compare a new song against an internal database of known songs. For instance, my reference song in B minor is "Comfortably Numb". If I hear a new song that sounds like it's in the same key, it must also be B minor. After I built up an internal collection for each key and practiced enough, it went from being a mechanical process to an intuitive one. It's not perfect, though; most of the "boring" keys sound similar. That is, I have a lot of trouble distinguishing between C, G, and F - fewer accidentals means less "color". In addition, keys within a fifth of each other can sound really similar since they're only one accidental apart. I'll often misidentify something in Bb minor as being in F minor, or something in E as being in B. Surprisingly though, half-step differences end up sounding very different. My wife and I watched Pitch Perfect recently, and during a scene where two women were singing "Titanium", the fact that they were singing it in B minor rather than C minor was extremely apparent.