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^*topipi$. 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^{pitext{-box}}=-15.9(2)times 10^{-11}$. As an application of the partial-wave formalism, we present a first calculation of $pipi$-rescattering effects in HLbL scattering, with $gamma^*gamma^*topipi$ helicity partial waves constructed dispersively using $pipi$ 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^{pitext{-box}} + a_{mu,J=0}^{pipi,pitext{-pole LHC}}=-24(1)times 10^{-11}$.