>>212172285They never really explain it properly even in the books.
But my assumption is that the cup was always a portkey designed to bring the winner back to the starting line for the winner celebration. Hogwarts normally prevents teleportation within the grounds, so the cup was given a special exemption. You couldn't use any ordinary portkey.
That's the reason for the whole tournament ploy. The triwizard cup was the only way to teleport Harry from within Hogwarts. Crouch fiddled with it to change the teleport destination the same way he did with the Goblet of Fire.
That's also why the cup was able to teleport Harry back to Hogwarts. That was the original destination.
Of course it's still retarded. He could have simply stunned Harry in private and flown out of the grounds on a broom with Harry in tow until he could apparate. That would be a much easier plan.