Achillles was keeping Hector's body and dragging it around the tomb of his friend to show he had avenged his friend in battle. Achilles was in horrible grief over the death of Patroclus.
...but Achilles still
wept for thinking of his dear comrade, and sleep, before whom all
things bow, could take no hold upon him. This way and that did he
turn as he yearned after the might and manfulness of Patroclus;
he thought of all they had done together, and all they had gone
through both on the field of battle and on the waves of the weary
sea. As he dwelt on these things he wept bitterly and lay now on
his side, now on his back, and now face downwards, till at last
he rose and went out as one distraught to wander upon the
seashore. Then, when he saw dawn breaking over beach and sea, he
yoked his horses to his chariot, and bound the body of Hector
behind it that he might drag it about. Thrice did he drag it
round the tomb of the son of Menoetius, and then went back into
his tent, leaving the body on the ground full length and with its
face downwards. But Apollo would not suffer it to be disfigured,
for he pitied the man, dead though he now was; therefore he
shielded him with his golden aegis continually, that he might
take no hurt while Achilles was dragging him.
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.