5. As shown in Figure $1, P$ is a point outside the square $A B C D, P A$ $=\sqrt{2}, P B=4$. Then the maximum length of $P D$ is ( ).
(A)5
(B) $4+\sqrt{2}$
(C) 6
(D) $4+\sqrt{3}$
5.C.

As shown in Figure 6, $\triangle P A D$ is rotated $90^{\circ}$ clockwise around point $A$ to get $\triangle P^{\prime} A B$. Therefore, $\triangle P^{\prime} A B \cong \triangle P A D$. Hence, $P^{\prime} B = P D$,
$$
\begin{array}{l}
P^{\prime} A = P A = \sqrt{2}, \\
\angle P A P^{\prime} = 90^{\circ}.
\end{array}
$$

Connecting $P^{\prime} P$, we have
$$
P^{\prime} P = \sqrt{P A^{2} + P^{\prime} A^{2}} = 2, \angle A P P^{\prime} = 45^{\circ}.
$$

Since $P D = P^{\prime} B \leqslant P^{\prime} P + P B = 2 + 4 = 6$ (equality holds when $P^{\prime}, P, B$ are collinear), the maximum value of $P D$ is 6.
At this time, $\angle A P B = 135^{\circ}$.