This question 'Would have known' vs 'could have known' is one of the most interesting questions I have encountered. I did a research about its use.
I suspect that in the linked question "I don’t know how the killer could have known the key code, but I’m sure that’s when he must have got in", we could roughly paraphrase it as "I don’t know how the killer would have been able to know the key code, unless somebody else had told him", as suggested by Frank's comment. Here "could + perfect infinitive" expresses past counterfactual meaning.
The other important use of "could + perfect infinitive" expresses past factual possibility, as suggested by HostileFork's answer.
And I quote here some extra examples from the Internet, adding some explanations of my own, so I might have a better understanding.
Which of them could be substituted with "would have known" or "could know" without considerable change in meaning?
I suspect when "could have known" expresses counterfactual meaning, they are more or less interchangeable with "would have known" in the following examples. When "could have known" is used for evaluating the past factual possibility they are more or less interchangeable with "could know".
Please help walk me through them.
#1. "My name is Elijah," the man says, inspecting her with dark eyes. "Your son - Malachi, is it? - asked me to help you."
...
He continues, "Like you, I'm a vampire, although I don't know how your son could have known (I'm a vampire) when he asked me to help you."https://www.fanfiction.net/s/10170561/1/Hope-s-What-We-Crave
Here the speaker is expressing surprise. We could roughly paraphrase it as "I don't know how it is possible for your son to have known..". Using "would have known" wouldn't fit with the context. And why not just simply say "I don't know how your son could know"? It seems neater.
#2. You're going to be playing the 2012 Vans Warped Tour. How excited are you? What are you looking forward to the most? Are there any other bands you're hoping to meet on the tour?
We are absolutely over the moon! I remember the day of our first show I said all I wanted was to play Warped Tour some day. I don't know how much I could have known about the festival at the time but I knew all my favourite bands played it so it feels really special to have reached that goal. We're all looking forward to catching up with the bands we've toured with and met over the past year of touring!
http://www.culturebrats.com/2012/02/seven-questions-in-heaven-with-tonight.html
I would reword it as "I don't know how much I could know about the festival at the time". I'm not sure if it's the intended meaning.
#3. I remember the day the transcript came and, that day, I was kinda freaking out that it was gonna come in the mail. I was checking the mailbox, and I got the mail before my parents could see it. They were blindsided by this. They had no idea that this was going on. I did everything I could to lie to them and tell them I was doing well. I don’t know how they could have known. They weren’t there. I was away at school, so it wasn’t like they saw me every day. There’s really no way they could have known. But in any case, I took the transcript from the mailbox and I hid it.
I think "could have known" here expresses counterfactuality; the parents didn't know his bad results. Using "would have known" would keep the intended meaning intact, I suppose.
#4. That spring I met a girl, or more precisely she met me. I was what is usually described as shy. In truth I was already somewhat socially and emotionally retarded. I had never really even talked to a girl. While my non-user and “normie” peer group were out going to social functions and starting to develop into young adults, I was always loaded and making no attempt at emotional or social growth. I avoided facing my fears and insecurities by not facing the real world. I don't know how she could have known the only way I would have been able to talk to her, but she found it by offering to smoke a joint. This was heaven for me. I didn't have to do anything - the pot did it for me.
https://www.marijuana-anonymous.org/book/our-stories/my-best-thinking-got-me-here
It seems to be a hypothetical scenario here. I suspect "would have known" is a possible alternative for "could have known" here while "could know" would not work here.
#5. I have some interest in collecting cards from TV shows and movies, and the current Panini set has been floating my boat a little, too. But I don't know how Dave could have known that. This is a pretty awesome bit of history. Dave sent many more cards. I don't have the time or the patience to show all of them. Rest assured, you'll see some of them in future posts.
I think "could have known" here expresses factual possibility, as in #1. We could roughly paraphrase it as "I don't know how it is possible for Dave to have known..". Seems "would have known" couldn't work here. Again, I would just say "I don't know how Dave could know that". Any different connotation conveyed?