5. 16 .

If $\left(a_{1}, a_{2}, a_{3}, a_{4}\right)=(1,2,3,6)$, then there are 16 ordered triples $(i, j, k)$ that satisfy the condition, and
$$
\begin{aligned}
( & \left.a_{i}, a_{j}, a_{k}\right) \\
= & (1,2,3),(1,2,6),(1,3,2), \\
& (1,3,6),(1,6,2),(1,6,3), \\
& (2,3,6),(2,3,1),(2,1,3), \\
& (2,1,6),(3,1,2),(3,1,6), \\
& (6,1,2),(6,1,3),(3,2,6), \\
& (3,2,1) .
\end{aligned}
$$

We now prove that the number of ordered triples $(i, j, k)$ that satisfy the condition cannot be 17.
Proof by contradiction.
Assume there are 17 ordered triples $(i, j, k)$ that satisfy the condition. Since the total number of ordered triples is $4 \times 3 \times 2=24$, these 24 ordered triples can be divided into eight disjoint subsets of the form
$$
\{(i, j, k),(j, k, i),(k, i, j)\}
$$

where $i, j, k$ are distinct.
By the pigeonhole principle, there exists a subset in which all three ordered triples satisfy the condition.

Assume for a permutation $(a, b, c, d)$ of $\left(a_{1}, a_{2}, a_{3}, a_{4}\right)$, we have
$$
(a, b)^{2}\left|c,(b, c)^{2}\right| a,(c, a)^{2} \mid b \text {. }
$$

Let $p^{\alpha} \|(a, b)$ (where $p$ is a prime and $\alpha$ is a non-negative integer). Then
$p^{2 \alpha}\left|c \Rightarrow p^{\alpha}\right|(b, c) \Rightarrow p^{2 \alpha} \mid a$
$\Rightarrow p^{\alpha}\left|(c, a) \Rightarrow p^{2 \alpha}\right| b \Rightarrow p^{2 \alpha} \mid(a, b)$.
Thus, $\alpha=0$, i.e., $(a, b)=1$.
Similarly, $(b, c)=(c, a)=1$.
If $d$ is coprime with two of $a, b, c$, then there exists a circular permutation of $a, b, c, d$ such that any two adjacent terms are coprime (first arrange $a, b, c$ in any circular permutation, then place $d$ between the two numbers it is coprime with), which is a contradiction.

Thus, $d$ is not coprime with at least two of $a, b, c$. Without loss of generality, assume $(b, d)>1,(c, d)>1$.
If $(b, d)^{2} \mid a$, then $(a, b)>1$, which is a contradiction, so $(b, d)^{2} \nmid a$, and $(d, b)^{2} \nmid a$;
If $(b, d)^{2} \mid c$, then $(b, c)>1$, which is a contradiction, so $(b, d)^{2} \nmid c$, and $(d, b)^{2} \nmid c$;
If $(c, d)^{2} \mid a$, then $(a, c)>1$, which is a contradiction, so $(c, d)^{2} \nmid a$, and $(d, c)^{2} \nmid a$;
If $(c, d)^{2} \mid b$, then $(b, c)>1$, which is a contradiction, so $(c, d)^{2} \nmid b$, and $(d, c)^{2} \nmid b$.
Therefore, at least 8 ordered triples $(i, j, k)$ do not satisfy $\left(a_{i}, a_{j}\right)^{2} \mid a_{k}$.

Hence, the number of ordered triples $(i, j, k)$ that satisfy the condition is at most 16.

In conclusion, the maximum number of ordered triples $(i, j, k)$ that satisfy the condition is 16.
5. Given positive integers $a_{1}, a_{2}, a_{3}, a_{4}$ satisfy: in any circular permutation of these four numbers, there exist two adjacent numbers that are not coprime. Find the maximum number of ordered triples $(i, j, k)$ such that $i, j, k \in \{1,2,3,4\}, i \neq j, j \neq k$, $k \neq i$, and $\left(a_{i}, a_{j}\right)^{2} \mid a_{k}$.