The meaning is that Harry is recalling a past action or behavior, and, while remembering it NOW, in the present of the narrative, he is judging it as stupid. The use of the Present Perfect here is necessary with the question word how together with the past modal construction beginning with the modal verb could. There is a definite tone of self-criticism in the question.
Could + a present tense verb can show possibility, and could have + a past participle usually shows a past possibility that did not occur. However, in WH-questions with how, the meaning can be quite different, as it is in your example, where the question often means that the action following could have did occur, and the questioner is asking why. Often, the question is rhetorical and judgmental. (I can think of only one exception where a WH-question with how and could have is not judgmental: How could I have done that?, in answer to, for example, a policeman accusing someone of a crime when that questioner has a solid alibi. In such a context, the questioner is asking (either sincerely or disingenously) for proof or a logical explanation of how they could have possibly committed the crime, but not conceding that they had done so; neither, obviously, are they judging themselves for a crime they have not admitted to having committed. There may be other such exceptions...)
In positive sentences using could have, there is not necessarily as strong a tone of criticism (For example, You could have helped sounds judgmental, but He could have been busy does not sound judgmental; the latter sentence is simply speculating about a past possibility), and in negative yes/no questions (Couldn't you have helped?) or WH-questions with how (either with first, second or third person pronouns), there often is a judgmental nuance (for example, How could I have been so stupid?, How could you have done that?, How could she have been so stupid?). However, the exception I provided above could be rephrased as either a negative yes/no question or a WH-question with how that is not judgmental: Couldn't he have been busy? or How could he have committed the crime, since he has a solid alibi?
(In the present tense in a WH-question with how, could + [be], a similar tone of judgmentalism can be shown, but with a present, ongoing meaning: How could I/he/she/they be so stupid? Often, the difference between How could he be so stupid? and How could he have been so stupid? is negligible.)
I hope this helps. Please let us know if you have any other questions.
Since the sentence uses could, I think you can just use be, have been, or had been. – kiamlaluno – 2013-02-11T13:06:38.213
1@kiamlaluno, No no no! Please consult some grammar books! Neither "could he be" or "could he had been" make sense; the former has a present meaning, and the latter is utterly ungrammatical. Only "could have been" makes sense and is grammatical. – Shawn Mooney – 2013-02-11T13:16:34.450
Since when is "Could I be right?" wrong? – kiamlaluno – 2013-02-11T13:31:15.743
@kiamlaluno, that is a good question, but "Could I be right?" is definitely a present tense situation. It means "Am I right, or am I wrong?," NOW. "Could I have been right?" means "Was I right, or was I wrong?," a past meaning. – Shawn Mooney – 2013-02-11T13:39:16.053
You said that "could he be" doesn't make sense. I guess that, for you, the question form of "they could be right" doesn't make sense. In your first comment, you were not speaking of differences between using be, and have been. Then, what I wanted to point out is that "Could he were be so stupid?" is not something said, and referring to the past event with could requires another type of past tense. – kiamlaluno – 2013-02-11T13:45:57.853
@kiamlaluno, "They could be right" is a present assessment, and of course it makes sense and is grammatical. You didn't actually give the question form, which would be "Could they be right?," but I agree with you that it is okay but always refers to a present assessment/evaluation. What other constructions do you think might work with "could" in this particular context to show a past meaning? I am certainly willing to consider them. – Shawn Mooney – 2013-02-11T14:28:50.673
@ShawnMooney Quoting what you said: "Neither 'could he be' or 'could he had been make sense." "Could [personal pronoun] be" does make sense, contrary to what you said, period. – kiamlaluno – 2013-02-11T14:37:00.940
Not period. Far from it. As I hope I have clearly explained before, a question using the form "Could [personal pronoun] be" only makes sense in a present evaluative/assessment context. If I have misunderstood your point (misunderstandings on my part are highly likely), please let me know. – Shawn Mooney – 2013-02-11T14:51:37.300
2@Shawn, kiamlaluno: Whilst it's true that *how could he had been so stupid?* is never valid, in such contexts it's perfectly common to say *how could he be so stupid?*. Perhaps it's partly because "stupidity" is often seen as an "enduring state", so if he was stupid in the past, he's still stupid now. Whatever - it's nitpicking to dispute the usage on logical/semantic grounds, since native speakers come out with it all the time. – FumbleFingers Reinstate Monica – 2013-02-11T23:03:04.203
@FumbleFingers, thank you for the feedback. I have also reconsidered kiamlaluno's feedback, which makes good sense. Just now, I have made a substantial re-edit to my original answer, based on your comments and also those of jwpat7; I would be grateful if any of you could review it and suggest any improvements. Thanks! – Shawn Mooney – 2013-02-12T14:17:52.827