Final answer:
The sentence in question is grammatically correct; 'I'd' is a contraction for 'I had' and 'that' refers to the exams which were unexpectedly fun.
Step-by-step explanation:
The sentence "I'd heard Hogwart's final exams were frightful, but that was fun." is grammatically correct. Here, I'd stands for I had, which is a past perfect contraction indicating that the hearing occurred before the exams took place. The word that refers to the experience of taking the exams, which the speaker is contrasting with their prior expectations by expressing that it was fun instead of frightful.