However he got them must've been legal - otherwise he'd have been charged.
One thing can be said for certain: Hagrid keeping Hippogriffs at Hogwarts wasn't a case of him acquiring illegal creatures as he sometimes does. When Draco gets bitten by Buckbeak, Lucius throws the full weight of his power into finding a way to punish Hagrid.
“– he’s complained to the school governors. And to the Ministry of Magic. Father’s got a lot of influence, you know. And a lasting injury like this –’ he gave a huge, fake sigh, ‘who knows if my arm’ll ever be the same again?”
- Harry Potter and the Prisoner of Azkaban, Chapter 7 (The Boggart in the Wardrobe)
Yet Hagrid isn't charged for the incident. We know Lucius is doing everything he possibly can to get Hagrid punished, and if he could tell the Ministry or school governors at all that keeping Hippogriffs around children was irresponsible, he would have.
“Dear Mr Hagrid,
Further to our inquiry into the attack by a Hippogriff on a student in your class, we have accepted the assurances of Professor Dumbledore that you bear no responsibility for the regrettable incident.”
- Harry Potter and the Prisoner of Azkaban, Chapter 11 (The Firebolt)
From this, we see that he's not held responsible, and that bringing Hippogriffs to Hogwarts isn't considered irresponsible by the authorities. It’s even mentioned in “Fantastic Beasts and Where to Find Them” that Hippogriff owners are required by law to put a Disillusionment Charm on them.
“Those who own a Hippogriff, for example, are bound by law to enchant the beast with a Disillusionment Charm to distort the vision of any Muggle who may see it. Disillusionment Charms should be performed daily, as their effects are apt to wear off.”
- Fantastic Beasts and Where to Find Them
This shows that owning a Hippogriff is itself legal, since if it was itself illegal, there’d be no lawful way to own one. As there is one, this shows that Hippogriffs can be owned legally.
It's unclear if Hagrid got them to Hogwarts himself or they were there first.
Hagrid never mentioned acquiring the Hippogriffs himself, like how he got Norbert and Fluffy. That certainly doesn't eliminate the possibility that he did, but it's never said. Conversely, it's also never said that they were at Hogwarts before Hagrid, or how long they’ve been there.
He had planned at least somewhat in advance to show his class Hippogriffs.
Hagrid tells Harry and Hermione that he thought Hippogriffs would make a good first lesson.
“School gov’nors have bin told, o’ course,’ said Hagrid miserably. ‘They reckon I started too big. Shoulda left Hippogriffs fer later … done Flobberworms or summat … jus’ thought it’d make a good firs’ lesson … ’s all my fault …”
- Harry Potter and the Prisoner of Azkaban, Chapter 6 (Talons and Tea Leaves)
He’d planned it somewhat in advance, whenever he’d actually gotten the Hippogriffs.