Harry has to compete because if he doesn't, he'll die (probably).
In what can only be described as the stupidest plot-twist ever, it turns out that in a competition designed to be entered by children, the Goblet is set to mete out a severe punishment to anyone who refuses to take part.
My reading was that since competing in the competition (the first task of which involves facing a giant man-eating dragon) is the lesser danger, this punishment must be either deadly or mind-destroying:
‘Finally, I wish to impress upon any of you wishing to compete that
this Tournament is not to be entered into lightly. Once a champion has
been selected by the Goblet of Fire, he or she is obliged to see the
Tournament through to the end. The placing of your name in the Goblet
constitutes a binding, magical contract. There can be no change of
heart once you have become champion. Please be very sure, therefore,
that you are whole-heartedly prepared to play, before you drop your
name into the Goblet
It appears that the three heads lack the ability to change or cancel the results, even if the Goblet throws a wobbly:
Bagman wiped his round, boyish face with his handkerchief and looked
at Mr Crouch, who was standing outside the circle of the firelight,
his face half hidden in shadow. He looked slightly eerie, the half
darkness making him look much older, giving him an almost skull-like
appearance. When he spoke, however, it was in his usual curt voice.
‘We must follow the rules, and the rules state clearly that those people whose names come out of the Goblet of Fire are bound to compete
in the Tournament.’
and
‘Empty threat, Karkaroff,’ growled a voice from near the door. ‘You
can’t leave your champion now. He’s got to compete. They’ve all got to
compete. Binding magical contract, like Dumbledore said. Convenient,
eh?’
and
Don’t you?’ said Moody quietly. ‘It’s very simple, Karkaroff. Someone
put Potter’s name in that Goblet knowing he’d have to compete if it
came out.’