Equivalence between dimensional contractions in Wasserstein distance and the curvature-dimension condition