Using prime factor decompositions and remembering $\mathrm{lcm}(p^a,p^b)=p^{\max(a,b)}$, $\mathrm{gcd}(p^a,p^b)=p^{\min(a,b)}$ for primes $p$, one reduces the claim to the equation
$\max(\min(a,b),c) = \min(\max(a,c),\max(b,c))$
for $a,b,c \in \mathbb{N}$. We have $a \leq b$ or $b \leq a$. By symmetry, we may assume $a \leq b$. Then the LHS is $\max(a,c)$, and the RHS also equals $\max(a,c)$ since $\max(a,c) \leq \max(b,c)$.
So actually the equation above holds in every linear order. The crux is that although $(\mathbb{N} \setminus \{0\},|)$ is not a linear order, it embeds into a product of linear orders, using prime factor decompositions. More generally we see that the lattice of ideals of a PID is distributive (which fails for other rings).