Hi welcome to the forum,
Past perfect can be troublesome for learners.
The sequence of events that took place in any situation is important when past perfect is used. We first must understand the time reference in which past perfect is used.
Based on the dialog, everything is correct. For illustration purpose, I will label them with numbers to identify the sequence.
1) Girl:“I'm sorry I behaved that way just now. You must have thought that I was stupid.” 1) Something she did caused her to believe that he thought of her as being stupid.
2) Boy: "I hadn't thought you were." 2) he responded to her question with a past perf. because prior to her asking, he had not thought of her as being stupid. The thought in question was prior to her question.
In a conversation, no one will fault you for saying “I didn't think you were” but “I haven't thought you were.” may present a misconception being that “haven’t thought” is present perf.
Another simple example to compare:
I hadn’t heard from John for a long time until he called me last weekend.
The blue part is an event happened sometime in the past. The purple part is the ending point of that past event. Therefore, events happened prior to another event should be expressed in past perfect. Hope my explanation is not causing you confusion.
![Big Smile [:D]](/emoticons/emotion-2.gif)