The detention actually was for a useful purpose. In fact, Hagrid specifically contrasts this useful detention with Malfoy's preferred detention which really is useless:
(All quotes from Chapter Sixteen of Philosopher's Stone.)
"But this is servant stuff, it's not for students to do. I thought we'd be copying lines or something, if my father knew I was doing this, he'd –"
"– tell yer that's how it is at Hogwarts," Hagrid growled. "Copyin' lines! What good's that ter anyone? Yeh'll do summat useful or Yeh'll get out. If yeh think yer father'd rather you were expelled, then get back off ter the castle an' pack. Go on!"
The specific purpose of the detention is to find an injured unicorn:
"Look there," said Hagrid, "see that stuff shinin' on the ground? Silvery stuff? That's unicorn blood. There's a unicorn in there bin hurt badly by summat. This is the second time in a week. I found one dead last Wednesday. We're gonna try an' find the poor thing. We might have ter put it out of its misery."
And indeed the detention was successful, as they found the unicorn:
Something bright white was gleaming on the ground. They inched closer.
It was the unicorn all right, and it was dead. Harry had never seen anything so beautiful and sad. Its long, slender legs were stuck out at odd angles where it had fallen and its mane was spread pearly-white on the dark leaves.