Using strain to uncover the interplay between two- and three-dimensional charge density waves in high-temperature superconducting YBa2Cu3Oy