Most of the answers here seem to assume that the cup would have been a portkey anyway, as part of the tournament. However, I believe this is absolutely incorrect. There does not appear to be a shred of evidence in the book that the cup was intended to be a portkey to transport the winner back to the edge of the maze. In fact there is quite a bit of evidence against this idea.
The most obvious line of evidence is that no one ever mentions that the cup is supposed to be a portkey. Bagman didn't mention it when he was telling the champions about the task a month in advance, nor did he mention it when the task was actually taking place.
Furthermore, it is explicitly confirmed that the champions had not been told that the cup was a portkey. From Chapter Thirty-Two:
Cedric looked down at the Triwizard Cup and then up at Harry.
"Did anyone tell you the cup was a Portkey?" he asked.
"Nope," said Harry.
Surely the champions would have been told that cup was a portkey if that had been planned as part of the tournament.
Additionally, Voldemort and Barty Crouch Jr. talk about the portkey in a fashion that very much seems to imply that it was not supposed to be a portkey if not for their meddling. From Chapter Thirty-Three (my emphasis):
"Why... by using Bertha Jorkins's information, of course. Use my one faithful Death Eater, stationed at Hogwarts, to ensure that the boy's name was entered into the Goblet of Fire. Use my Death Eater to ensure that the boy won the tournament — that he touched the Triwizard Cup first — the cup which my Death Eater had turned into a Portkey, which would bring him here, beyond the reach of Dumbledore's help and protection, and into my waiting arms. And here he is... the boy you all believed had been my downfall...."
From Chapter Thirty-Five (my emphasis):
"He asked me whether I was ready to risk everything for him. I was ready. It was my dream, my greatest ambition, to serve him, to prove myself to him. He told me he needed to place a faithful servant at Hogwarts. A servant who would guide Harry Potter through the Triwizard Tournament without appearing to do so. A servant who would watch over Harry Potter. Ensure he reached the Triwizard Cup. Turn the cup into a Portkey, which would take the first person to touch it to my master. But first —"
"I offered to carry the Triwizard Cup into the maze before dinner," whispered Barty Crouch. "Turned it into a Portkey. My master's plan worked. He is returned to power and I will be honored by him beyond the dreams of wizards."
Additionally, when Harry tells what happened, the first thing he says is that the cup was a portkey, as if that was something novel. From Chapter Thirty-Five:
"What happened. Harry?" the man asked at last as he lifted Harry up the stone steps. Clunk. Clunk. Clunk. It was Mad-Eye Moody. "Cup was a Portkey," said Harry as they crossed the entrance hall. "Took me and Cedric to a graveyard... and Voldemort was there... Lord Voldemort..."
And finally, when Harry landed outside the maze it seems obvious from the reaction of the crowd that they were not expecting a portkey. From Chapter Thirty-Five:
A torrent of sound deafened and confused him; there were voices everywhere, footsteps, screams.... He remained where he was, his face screwed up against the noise, as though it were a nightmare that would pass....
(This was before they knew that Cedric was dead (which is only made known several paragraphs later), so the reaction was to the mere fact that Harry and Cedric had portkeyed to that location.)
From the above evidence I think it seems pretty clear that the cup was not intended to be a portkey at all. So now we need a different reason for why it brought Harry back.
This seems to be the only example of a two-way portkey in the books, so we don't have that much information to work with. In any case, we can assume that there are two types of portkeys: ones that take you to a destination, and ones that take you to a destination and back (or to an additional destination).
The portkey in this case was clearly a multiple-use portkey, which simply means that someone enchanted it to travel to more than one destination. Being that Barty Crouch Jr. is the one who turned the cup into a portkey, we have two options: Either he intended for the cup to bring Harry back, or he unintentionally made the cup bring Harry back. For the latter option we would have to assume that he wasn't paying so much attention when he made the portkey and accidentally set it as a two-way portkey instead of a one-way portkey. This is somewhat difficult to suggest, because the cup did not return Harry to his starting point; it returned him to the edge of the maze. If it was a simple mistake of making it a two-way portkey we would expect it to bring Harry back to the middle of the maze where he started from. The fact that it brought him somewhere else would seem to indicate that that location was specifically programmed. However, we can perhaps mitigate this difficulty by surmising that portkey destinations are not set precisely to the exact square milometer. Perhaps they simply bring you to a more general area like Stoatshead Hill, or the maze.
If the portkey was intentionally programmed to bring Harry back, we need to come up with a reason why this would have been desirable. Another answer here suggested that the goal was for Voldemort and the Death Eaters to be able to go straight to Hogwarts and attack after killing Harry. However, there does not appear to be any evidence that there was ever such a plan, and from the continuation of the story it seems that Voldemort had planned on keeping his return a secret. From Chapter Five of Order of the Phoenix:
“You weren’t supposed to survive!” said Sirius.
“Nobody apart from his Death Eaters was supposed to
know he’d come back. But you survived to bear
“And the very last person he wanted alerted to his
return the moment he got back was Dumbledore,”
said Lupin. “And you made sure Dumbledore knew at
(Granted, this information is coming from the Order of the Phoenix so we can't say for certain that it's reliable vis-a-vis Voldemort’s actual intentions.)
Therefore, there should be a different reason why Harry's return was planned. Here are two possibilities:
Harry's return would decrease the suspicion.
If Harry had simply disappeared and not returned everyone would have been extremely suspicious about what happened. When he failed to show up and he wasn't inside the maze everyone's top priority would have been to find him. It is possible that such an influx of activity relating to Harry's disappearance would have led to finding some clues about what happened. On the other hand, if Harry returns back to Hogwarts the immediate priority is very different. No one is missing so there is no need for all resources to be immediately diverted towards an investigation. Instead, the priority would be to deal with the appearance of a dead student and all that that entails. Of course, there would likely be an investigation into his death eventually, but it would probably be less intense and less immediate than if he was still missing. Thus, Crouch Jr. may have brought Harry back to give himself this advantage (however much it would actually be worth).
Harry's return would serve as confirmation that the plan had succeeded.
If Harry returns to Hogwarts dead, Crouch Jr. has his confirmation that everything went according to plan. Harry's body would not have returned if Voldemort had not successfully come back and killed Harry. Throughout the series it seems that wizards have very few good ways of immediate communication; this would be a simple way to let Crouch Jr. know that everything had worked out. While he would have felt the Dark Mark burning, it seems from his initial conversation with Harry that he wasn't entirely certain that Voldemort had truly come back: From Chapter Thirty-Five:
"What happened. Harry?" the man asked at last as he lifted Harry up the stone steps. Clunk. Clunk. Clunk. It was Mad-Eye Moody.
"Cup was a Portkey," said Harry as they crossed the entrance hall. "Took me and Cedric to a graveyard... and Voldemort was there... Lord Voldemort..."
Clunk. Clunk. Clunk. Up the marble stairs...
"The Dark Lord was there? What happened then?"
"Killed Cedric... they killed Cedric...."
Clunk. Clunk. Clunk. Along the corridor...
"Made a potion... got his body back...."
"The Dark Lord got his body back? He's returned?"
"And the Death Eaters came... and then we dueled...."
"You dueled with the Dark Lord?"
"Got away... my wand... did something funny.... I saw my mum and dad... they came out of his wand...."
Thus, the purpose of the portkey coming back to Hogwarts may have been to provide full confirmation of the plan's success.
Importantly, though, even using the answer that the cup was meant to be a portkey all along, we would still have to introduce the novel idea that a portkey can go to multiple destinations, plus we would still not know why Crouch Jr. allowed it to return to Hogwarts. Since we anyway have to grant the existence of a new type of portkey and come up with a reason for why Crouch Jr. wanted Harry to return, we don't gain anything by positing the additional novelty that the cup was intended to be a portkey all along.
And of course, there is always the possibility that the correct answer is as suggested in the two deleted answers — that this was a plot convenience, or that JK Rowling didn't think it through.