Hector was the son of King Priam and as such an enemy of Achilles. He and Achilles were told by different agents of Jove to go along with the ransom of the body. Achilles' mother came to him and told him that he was behaving badly in regard to desecrating a dead body rather than giving him the proper funeral rites. And, the goddess Iris came to Priam and told him to take a ransom to Achilles for the body of Hector.

It was dangerous because Priam had to literally cross enemy lines, go through enemy gates, and enter the house of Achilles to reclaim the body of his son. Achilles could have easily killed him too.