It's neither to me.
If it's a cleft clause then the original sentence should be rewritten in this way: "it's for the first time that Hermione had ever failed...."which is equivalent to " Hermione had failed to answer a teacher's question for the first time"
Here if it's written so, then it will be object to the context meaning.
But what we say "dummy-it" is more often referred to nothing but "weather, date, etc..
But here "it" refers to some kind of situation.
So I really doubt about the sentence and I'm wondering if there should be some punctuation mark which separates the two parts. Or simply put an "and" in the middle, which would be rewritten as " It was the first time and Hermione had ever ...blah"