5. Let $Q_{+}$ be the set of all positive rational numbers. Find all functions $f: \mathbf{Q}_{+} \rightarrow \mathbf{Q}_{+}$ such that for all $x, y \in \mathbf{Q}_{+}$, we have
$$
f\left(f^{2}(x) y\right)=x^{3} f(x y) .
$$
5. The function that satisfies the condition is $f(x)=\frac{1}{x}$.

In equation (1), take $y=1$. Then
$$
f\left(f^{2}(x)\right)=x^{3} f(x) \text {. }
$$

If $f(x)=f(y)$, then
$$
\begin{array}{l}
x^{3}=\frac{f\left(f^{2}(x)\right)}{f(x)}=\frac{f\left(f^{2}(y)\right)}{f(y)}=y^{3} \\
\Rightarrow x=y .
\end{array}
$$

Therefore, the function $f$ is injective.
In equation (2), replace $x$ with $xy$, and in equation (1), replace $(x, y)$ with $\left(y, f^{2}(x)\right)$, we get
$$
\begin{array}{l}
f\left(f^{2}(x y)\right)=(x y)^{3} f(x y) \\
=y^{3} f\left(f^{2}(x) y\right)=f\left(f^{2}(x) f^{2}(y)\right) .
\end{array}
$$

Since $f$ is injective, we have
$$
\begin{array}{c}
f^{2}(x y)=f^{2}(x) f^{2}(y) \\
\Rightarrow f(x y)=f(x) f(y) .
\end{array}
$$

Let $x=y=1$. We get $f(1)=1$.
Thus, for all positive integers $n$,
$$
f\left(x^{n}\right)=f^{n}(x) \text {. }
$$

Therefore, equation (1) becomes
$$
f^{2}(f(x)) f(y)=x^{3} f(x) f(y),
$$

which simplifies to $f(f(x))=\sqrt{x^{3} f(x)}$.
Let $g(x)=x f(x)$.
From equation (3), we have
$$
\begin{array}{l}
g(g(x))=g(x f(x))=x f(x) f(x f(x)) \\
=x f^{2}(x) f(f(x))=x f^{2}(x) \sqrt{x^{3} f(x)} \\
=(x f(x))^{\frac{5}{2}}=g^{\frac{5}{2}}(x) .
\end{array}
$$

By mathematical induction, for each positive integer $n$ we have
$$
\underbrace{g(g(\cdots g(x) \cdots))}_{n+1 \text { times }}=(g(x))\left(\frac{5}{2}\right)^{n} \text {. }
$$

In equation (4), for a fixed $x$, the left side of equation (4) is always a rational number, so $(g(x))\left(\frac{5}{2}\right)^{n}$ is a rational number for each positive integer $n$.
We will prove that only $g(x)=1$ is possible.
Assume $g(x) \neq 1$. Let $g(x)=p_{1}^{\alpha_{1}} p_{2}^{\alpha_{2}} \cdots p_{k}^{\alpha_{k}}$, where $p_{1}, p_{2}, \cdots, p_{k}$ are distinct primes, and $\alpha_{1}, \alpha_{2}, \cdots, \alpha_{k}$ are non-zero integers. Then equation (4) becomes
$$
\begin{array}{l}
\underbrace{g(g(\cdots g(x) \cdots))}_{n+1 \text { times }}=(g(x))^{\left(\frac{5}{2}\right)^{n}} \\
=p_{1}^{\left(\frac{5}{2}\right)^{n} \alpha_{1}} p_{2}^{\left(\frac{5}{2}\right)^{n} \alpha_{2}} \cdots p_{k}^{\left(\frac{5}{2}\right)^{n} \alpha_{k}} \text {, } \\
\end{array}
$$

where the exponents must be integers. However, when $n$ is sufficiently large, this is impossible (for example, when $2^{n} \times \alpha_{1}$, $\left(\frac{5}{2}\right)^{n} \alpha_{1}$ is not an integer). Therefore, $g(x)=1$, i.e., for all $x \in Q_{+}, f(x)=\frac{1}{x}$.
Thus, the function $f(x)=\frac{1}{x}$ satisfies equation (1), i.e.,
$$
f\left(f^{2}(x) y\right)=\frac{1}{f^{2}(x) y}=\frac{1}{\left(\frac{1}{x}\right)^{2} y}=\frac{x^{3}}{x y}=x^{3} f(x y) .
$$