As tchrist and Matt Эллен tell you, this is 'eye dialect'. It doesn't represent any particular pronunciation: it's just JKR's way of signalling that you should 'hear' Hagrid speaking a non- or sub-standard variety of the language.
The inconsistency comes about because JKR's usual (and arbitrary) use of {ter} trips her up. JKR (and, presumably, Hagrid) speaks a non-rhotic dialect, so she naturally spells an unstressed to with an {r}, which to her (and generations of British writers) represents a contrast between 'proper' /tu/ and 'dialect' /tə/.
(Never mind the fact that that's how everybody actually pronounces to in most contexts).
But in most non-rhotic English dialects, when syllable-terminal /r/ occurs appears before a vowel it is pronounced, in effect as the head of the following syllable. JKR does not want to suggest the pronunciation /tərə/ for to a; so she changes her arbitrary {ter} to an equally arbitrary {teh}.
(Never mind the other fact that it is precisely in this context that most speakers, standard or non-, will actually pronounce to as /tu/. We're dealing with literary convention, not phonetic fact.)
HP 1 (Harry Potter and the Philosopher's/Sorcerer's Stone) was published in 1997, which I suppose was before the chat/text spelling {teh} for {the} became current. Or perhaps I am wrong in that supposition, and JKR was merely not at the time aware of the {teh} convention, either because she was too old (32) and too literarily educated (BA Exeter in French and Classics) to frequent circles where it was current or because she was too poor to have internet access.