It is obvious that someone (at least Dumbledore) knew about the conditions Harry's been kept in: the letters were addressed to "cupboard under the stairs" and then to "the smallest bedroom". Moreover, they knew Harry wasn't receiving his letters, hence the hundreds of letters, sneaking them in the milk bottles and flowing through the fireplace.
Given that Dumbledore trusts Hagrid enough to get the Philosophers Stone from the Grinngotts, and prior to that to deliver Harry to Godric's Hollow, and overall his trust in Hadrid is doubtless:
Professor McGonagall opened her mouth, changed her mind, swallowed, and then said, "Yes -- yes, you're right, of course. But how is the boy getting here, Dumbledore?" She eyed his cloak suddenly as though she thought he might be hiding Harry underneath it.
"Hagrid's bringing him."
"You think it -- wise -- to trust Hagrid with something as important as this?"
"I would trust Hagrid with my life," said Dumbledore.
Harry Potter and the Philosopher's Stone - Chapter 1 The Boy Who Lived
So it's rather unlikely that Hagrid was unaware of Harry's knowledge or condition, because why would Dumbledore keep something like this from Hagrid while fully trusting him?
The out-of-universe answer suggests that
Essentially it provided JK a device to reveal some of the key information to the audience, as they were surprised with Harry.
Reddit answer here