5. In any permutation $a_{1}, a_{2}, \cdots$, $a_{7}$ of $1,2, \cdots, 7$, the number of permutations where any two adjacent numbers are coprime is ( ) kinds.
(A) 288
(B) 576
(C) 864
(D) 1152
5.C.

First, let the numbers $1, 3, 5, 7$ be fully permuted, which gives $\mathrm{A}_{4}^{4}=24$ ways; then arrange the number 6, since the number 6 should not be adjacent to 3, in the already arranged sequence, there are 5 gaps between 1, 3, 5, 7 and at the beginning and end, excluding the two gaps around 3, there are 3 gaps left to place the number 6, so there are 3 ways to place the number 6; finally, arrange the numbers $2, 4$, in the remaining 4 gaps, place the numbers 2, 4, which gives $\mathrm{A}_{4}^{2}$ ways.
Therefore, the total number of ways is $\mathrm{A}_{4}^{4} \times 3 \times \mathrm{A}_{4}^{2}=864$.