My attempt:
Given,
$$\sqrt{(\log_2x)^2 - 5|\log_2x| + 6} \le 2\sqrt{5}$$
Taking $t=|\log_2x|$:
$$\sqrt{t^2-5t+6} \le 2\sqrt{5}$$
I know that squaring both sides will lead to extraneous solutions. In fact, I solved the rest of the problem by squaring sides and got $x \in \left[\dfrac{1}{128},128\right]$ whereas the correct answer according to Wolfram Alpha is $x \in \left[\dfrac{1}{128},\dfrac{1}{8}\right] \cup \left[\dfrac{1}{4}, 4\right] \cup [8,128]$.
What is the correct way of solving this problem that avoids extraneous solutions?
There is nothing wrong with squaring both sides, as long as you keep in mind that you are interested only in those $t$'s such that $t^2-5t+6\geqslant0$, which means that $t\leqslant2$ or that $t\geqslant3$. Since, on the other hand$$t^2-5t+6\leqslant20\iff t\in[-2,7],$$you have\begin{align}\sqrt{t^2-5t+6}\leqslant2\sqrt5&\iff t\in[-2,2]\cup[3,7]\\&\iff\bigl|\log_2(x)\bigr|\in[0,2]\cup[3,7].\end{align}