Most themes or sections of themes usually close with two cadence chords: dominant and tonic, in that order. In Hedwig's Theme, they do end on the tonic (in the last bar above) but the chord preceding it is not the dominant, it is the dominant of the dominant, which leads us to expect the dominant chord next.