“Is that you, Filch? Hurry up, I want ter get started.”
Harry’s heart rose; if they were going to be working with Hagrid it wouldn’t be so bad. His relief must have showed in his face, because Filch said, “I suppose you think you’ll be enjoying yourself with that oaf? Well, think again, boy — it’s into the forest you’re going and I’m much mistaken if you’ll all come out in one piece.”
Harry Potter and the Sorcerer's Stone, Chapter 15, The Forbidden Forest
Yes, Dumbledore requested students to avoid the forbidden forest. But that is to ensure that students don't go into the forest when they are alone without adult supervision. In this case, Hagrid would be around to take care of the students.
“There’s nothin’ that lives in the forest that’ll hurt yeh if yer with me or Fang,” said Hagrid.
Harry Potter and the Sorcerer's Stone, Chapter 15, The Forbidden Forest
I think in case of detention, Dumbledore would know which teacher/staff would handle detention, but he would not know how they will manage it. Dumbledore would not have expected Hagrid to divide the group.
“An’ keep ter the path. Right, now, we’re gonna split inter two parties an’ follow the trail in diff’rent directions. There’s blood all over the place, it must’ve bin staggerin’ around since last night at least.”
Harry Potter and the Sorcerer's Stone, Chapter 15, The Forbidden Forest