This is from "The Lion King":
Nala: And your mother, what will she think?
Simba: She doesn't have to know. Nobody has to know.
Nala: Of course they do!
Why doesn't she reply: "Of course they have!" ?
To omit the rest of the sentence, you need an auxiliary verb. And sometimes, have is an auxiliary verb:
Have you taken out the trash?
Yes, I have [taken out the trash].
Here, have is an auxiliary verb, so the rest of the sentence can be omitted as long as it can be understood from context.
If you don't have an auxiliary verb, you can insert the meaningless auxiliary do:
You like eggs, right?
Yes, I do [like eggs].
Note that you can't simply say "Yes, I like", because like isn't an auxiliary verb. You need an auxiliary to omit the rest of the sentence.
And in your example, have is not an auxiliary. In this sense, it's a lexical verb:
She doesn't have to know. Nobody has to know.
Of course they have to know!
Since it's not an auxiliary verb, the rest of the sentence can't be omitted. But if we insert the meaningless auxiliary do:
Of course they do [have to know]!
Then we can omit it.