  In this third paper of a series dedicated to a dispersive treatment of the
hadronic light-by-light (HLbL) tensor, we derive a partial-wave formulation for
two-pion intermediate states in the HLbL contribution to the anomalous magnetic
moment of the muon $(g-2)_\mu$, including a detailed discussion of the
unitarity relation for arbitrary partial waves. We show that obtaining a final
expression free from unphysical helicity partial waves is a subtle issue, which
we thoroughly clarify. As a by-product, we obtain a set of sum rules that could
be used to constrain future calculations of $\gamma^*\gamma^*\to\pi\pi$. We
validate the formalism extensively using the pion-box contribution, defined by
two-pion intermediate states with a pion-pole left-hand cut, and demonstrate
how the full known result is reproduced when resumming the partial waves. Using
dispersive fits to high-statistics data for the pion vector form factor, we
provide an evaluation of the full pion box,
$a_\mu^{\pi\text{-box}}=-15.9(2)\times 10^{-11}$. As an application of the
partial-wave formalism, we present a first calculation of $\pi\pi$-rescattering
effects in HLbL scattering, with $\gamma^*\gamma^*\to\pi\pi$ helicity partial
waves constructed dispersively using $\pi\pi$ phase shifts derived from the
inverse-amplitude method. In this way, the isospin-$0$ part of our calculation
can be interpreted as the contribution of the $f_0(500)$ to HLbL scattering in
$(g-2)_\mu$. We argue that the contribution due to charged-pion rescattering
implements corrections related to the corresponding pion polarizability and
show that these are moderate. Our final result for the sum of pion-box
contribution and its $S$-wave rescattering corrections reads
$a_\mu^{\pi\text{-box}} + a_{\mu,J=0}^{\pi\pi,\pi\text{-pole LHC}}=-24(1)\times
10^{-11}$.
