5. Let $a$ be a real number. To ensure that for any $x \in (-\infty, 1) \cup (5,+\infty)$, we have
$$
x^{2}-2(a-2) x+a>0 \text {. }
$$

Then the set of all $a$ that satisfy the above requirement is ( ).
(A) $(-\infty, 5]$
(B) $(1,4)$
(C) $(1,7]$
(D) $(1,5]$
5. D.

Let $f(x)=x^{2}-2(a-2) x+a$.
We discuss the following two cases.
(1) $f(x)$ has no zeros.

In this case, $f(x)$ is always greater than 0, which clearly meets the requirement. By $\Delta=4(a-2)^{2}-4 a<0 \Rightarrow a \in(1,4)$.
(2) $f(x)$ has zeros.
In this case, by the graph of the function, $f(x)$ meets the requirement only when
$$
f(1) \geqslant 0, f(5) \geqslant 0,1 \leqslant a-2 \leqslant 5,
$$

and $f(a-2) \leqslant 0$.
By $f(1) \geqslant 0, f(5) \geqslant 0 \Rightarrow a \leqslant 5$;
By $1 \leqslant a-2 \leqslant 5 \Rightarrow 3 \leqslant a \leqslant 7$;
By $f(a-2) \leqslant 0 \Rightarrow a \leqslant 1$ or $a \geqslant 4$.
Taking the intersection, we get $a \in[4,5]$.
In summary, $a \in(1,4) \cup[4,5]=(1,5]$.