Measurement of the dipion mass spectrum in $X(3872) to J/psi pi^+ pi^-$ decays