I had the misfortune of having a friend in high school who could listen to something and transcribe it. I remember at band camp watching him with a cassette player and manuscript player transcribing an instrumental break from a Chicago song. He'd play a couple seconds, score it out, then play a couple more seconds until he was done.
I say misfortune because I assumed this was a binary thing: you either could do it or you couldn't, and I was in the latter category. Later in life, I found that it was a learnable skill (probably what did more than anything else for me in developing my ear was being part of the cathedral choir and doing a lot of sight singing in harmony) (another aside, having done a lot of church music over the years, it was interesting to see the level of musicianship of the cathedral choir, and I was in the larger amateur group rather than the smaller professional group—where in most church choirs, each section would have their part played at the piano and they'd sing it back, the cathedral choir would have all four parts played together at the piano and everyone would sing back in harmony. The professionals didn't bother with the piano part and just sight-sang everything, including some really tricky harmonies, like having the sopranos sing a high F against an E minor chord in the lower voices.) At my peak, I was able to work on writing music while walking without any instrument and come home and transcribe what I'd written including all the harmonizations. I've lost some of that skill from lack of practice in the years since and I had to use Capo to recover the chord progression of a piece I wrote where I couldn't remember one of the chords in the middle 8.
So bottom line, there are some people for whom this comes naturally but it is absolutely a learnable skill.