I don't think this is true, $\pi_5(G)$ has little to do with anomalies, at least not in any direct way.
The general statement is: triangle anomalies for a given symmetry $G$, in $d$ dimensions, are classified by the free part of $\Omega_{d+2}(G)$. Here $\Omega_n(G)$ denotes the cobordism group of $G$, namely the collection of $n$ dimensional manifolds $M_n$ with a prescribed $G$-bundle, modulo the identification $M_n\sim M'_n$, where $\sim$ denotes the existence of an $(n+1)$-dimensional manifold $M_{n+1}$ such that $\partial M_{n+1}=M_n\sqcup \bar M_n'$, and such that the $G$-bundle extends smoothly.
Both $\Omega_\bullet(G)$ and $\pi_\bullet(G)$ measure topological obstructions of manifolds equipped with $G$-structures. So they carry some overlapping information. But the correct object to look at is $\Omega$, not $\pi$.
[More precisely, if you want $G$-anomalies you probably want to look at the reduced cobordism group $\Omega_{d+2}(G)=\tilde \Omega_{d+2}(G)\oplus \Omega_{d+2}(pt)$. I believe $\Omega_n(pt)$ may have a free part only if $n$ is a multiple of $4$, but the details (which are above my paygrade) might depend on which structure you want your manifolds to carry. The $G$-independent part $\Omega_n(pt)$ measures purely gravitational anomalies. This only plays a role in $d=2\mod4$ dimensions so irrelevant in $d=4$; but it is essential in e.g. $d=2$ where $\Omega_4(pt)=\mathbb Z$ is the famous central charge of a CFT, which constrains the number of spacetime dimensions in String Theory to $D=10$ or $D=26$.]
In four dimensions, for example for the ABJ anomaly, one has $\Omega_6(U(1))=\mathbb Z^2$, where one factor is the cubic anomaly $J^3$ and the other one is the mixed $U(1)$-grav part, $JT^2$, where $J$ is the current for $U(1)$ and $T$ is the energy-momentum tensor. But the group $U(1)=S^1$ has trivial $\pi_i$ for $i>1$ so it is clear that $\pi$ will miss anomalies. You really want to look at $\Omega$, not $\pi$.
To make things even more confusing, one can also look at homology groups $H_\bullet(G)$, which are some sort of linear approximation to $\pi_\bullet(G)$. These homology groups also measure topological obstructions, so they also carry some information in $\Omega_\bullet$. But, again, the correct object to look at is $\Omega$, not $\pi$ nor $H$.
That being said, it is true that $H^n(G,\mathbb Z)$ is a decent first order approximation to $\Omega_n(G)$, so it captures some anomalies. It misses all the mixed $G$-grav anomalies, but it does see many pure $G$-anomalies, at least for sufficiently well-behaved $G$. In this sense, triangle anomalies are approximately characterised by $H^{d+2}(G,\mathbb Z)$. This group turns out to be isomorphic to $H^{d+1}(G,U(1))$, which famously classifies Chern-Simons terms in $d+1$ dimensions. And these terms do indeed characterise some triangle anomalies in $d$ dimensions, via the Wess-Zumino descent procedure. So, to this approximation, it is true that triangle anomalies in $d=4$ are classified by $H^5(G,U(1))$ (note, again, $H^5$ and not $\pi_5$!)