  The role of lattice dynamics in unconventional high-temperature
superconductivity is still vigorously debated. Theoretical insights into this
problem have long been prevented by the absence of an accurate first-principles
description of the combined electronic, magnetic, and lattice degrees of
freedom. Utilizing the recently constructed r$^2$SCAN density functional that
stabilizes the antiferromagnetic (AFM) state of the pristine oxide
YBa$_2$Cu$_3$O$_6$, we faithfully reproduce the experimental dispersion of key
phonon modes. We further find significant magnetoelastic coupling in numerous
high energy Cu-O bond stretching optical branches, where the AFM results
improve over the soft non-magnetic phonon bands.
