Welcome to math.SE!
But my question is which "t" do we choose and how do we proceed to
choose the right one (see examples 1 and 2) ?
Think about how you would write proofs in the real world. If an exam asked you to prove that discontinuous functions exist, you would write something like "Consider the function $x \mapsto \mathrm{sgn}(x)$...", and then you would follow that by writing a proof that $x \mapsto \mathrm{sgn}(x)$ is discontinuous.
Nothing stops you from writing "Consider the function $x \mapsto x^2$..." instead, except for the fact that you won't be able to finish the proof that way: you can't prove that $x \mapsto x^2$ is discontinuous (because it isn't).
Formally, what you're doing while writing the exam amounts to using $D_\exists$ on the formula $\exists x. \neg \mathrm{continuous}(x)$, choosing $t$ to be $x \mapsto \mathrm{sgn}(x)$, and then finishing with a proof of $\neg \mathrm{continuous}(t)$.
There is no general method for choosing $t$. To choose the appropriate $t$, you need to know why the thing that you're trying to prove actually holds.
This rule says that "x" must not occur free anywhere, otherwise we
can't use it. But if we come to a situation where "x" is free
somewhere, do we have to rename it so that we can use the rule ?
That is correct.
In this example, I don't understand why "y" is replaced by "z" (1),
it doesn't say in the rule that we must do this. For (2), we applied
the rule and replaced "y" by a term "z". Did we choose "z"
purposefully ?
Yes. In the first example, we made two choices, since we had two $D_\exists$ rules. First, we chose $t$ to be $z$, and then we chose $t$ to be $x$. This was done purposefully: we had $P(x,z)$ on the left of the turnstile ($\vdash$). To finish the proof, we needed to have the same thing on both the left and the right. But these choices of $t$ were the only ones that could achieve this objective.
If it helps, you can think of $P(x,z) \vdash \exists y. \exists x. P(x,y)$ as the following exam question: "given that $z$ is the parent of $x$, prove that there are two people such that one is the parent of the other". You would just say "well, sure, in particular z is the parent of x", and conclude the proof. But this is exactly what the formal uses of $D_\exists$ amount to.
I have the same kind of question for this one. We replaced the
variable "x" by "z". Does it make a difference if we have chosen
another variable like "a" or did we choose "z" purposefully ?
The choice matters, for essentially the same reason. We have $R(z)$ on the left-hand side. The finish the proof, we have to have the same formula appear on both sides of the turnstile. So $z$ is a good choice: it ensures that we will eventually have $R(z)$ on the right-hand side as well.
Substituting $a$ instead of $z$ would have left us with $R(z), R(y) \vdash R(a)$, and there's no way to continue that proof: none of the rules can be applied.
(What about substituting $y$? That would not work either: I'll leave you to think about why.)