The name of the phenomenon is scope marking. This is a complicated issue because it is about forming questions in multiple embedded clauses...
So, "was" is not a real question word but it is a place-holder, a scope-marker. It is needed to mark the point at which the embedded question starts, although the real question word "wozu" cannot appear there. But the "wozu" is the core of what the question is about: "Er denkt, er hat ein Recht dazu"; "He thinks he is entitled to it" – to what? Whatever, I don't care. So the predicate "es ist mir egal" introduces variants and provokes the (indirect) question.
This doesn't change when the whole thing is additionally described from the other's point of view, embedding it under the verb "think": "He thinks he is entitled to something, but I don't care what it is." – Note that what Tilman Schmidt writes above is not correct: "Ich denke, wozu ich ein Recht habe" is actually ungrammatical. Or if you manage to get it, it is the wrong question. The basic message is: "I don't care what..." and not "he thinks what...".
Now, let's get to building up the indirect question. The question has to follow the predicate I-don't-care: "I don't care (give a damn), what he thinks he is entitled to." What is different in German, however, is that you have to use a compound question word "to what = wozu", and additionally the verb "entitled to" corresponds to a construction with a noun. So you would get:
- Es ist mir egal, wozu er denkt, dass er ein [Recht __] hat".
This is a structure that you might expect, and if it's acceptable it would show that the verb "denken" does not embed a question (because the paraphrase has "dass", indicating a declarative clause). So when you start analysing the example in terms of a question "was denkt er...", you are stuck and you cannot integrate the rest of the clause with the question word "wozu" into the structure.
DavidVogt has said in a comment that he finds the above example ok, but in my intuition it is not quite grammatical. Maybe it's a borderline case. In any case, it strains the grammar because you are moving a prepositional phrase (wozu = to what) and it depends on the noun "Recht", not as in English on the verb. So in German you have to dig too deep to find the place that the question word relates to, or to put it differently: the distance covered when you prepose the question word "wozu" to too long. (This is a classic topic in the theory of "wh-movement" and "subjacency" in Generative Grammar).
But the question word has to be preposed, because the phrase "I don't care" is what demands that the following clause should be an indirect question.
So the solution in German is to leave the question word "wozu" in a deeper clause and indicate the size of the question (Q) by a dummy "was". The structure can be developed in a stepwise fashion:
- Es ist mir egal Q:[Sie denken, [Sie haben ein Recht wozu]]
- Es ist mir egal Q: [Sie denken, [wozu Sie ein Recht haben]]
- Es ist mir egal [was Sie denken, [wozu Sie ein Recht haben]]
So here, "Q:Sie denken Sie haben ein Recht wozu" means in a less grammatical and more logical notation: "I don't care about which x it is such that you think that you are entitled to x"
By the way, this can also be extended: "Was meinst du, was sie glaubt, wen sie gesehen hat?" (question is about the x such that: Du meinst, dass sie glaubt, dass sie x gesehen hat") (example from Haider, see below).
*
Literature: Hubert Haider: The syntax of German, Cambridge UP 2010, Chapter 3.3: "Partial wh-movement".
Es ist mir egal, wozu ...
andEs ist mir egal, was Sie denken, wozu ...
are both grammatically correct but convey different meanings.