I understand that the term valency refers to the number of bonds an element would be able to form with either chlorine or hydrogen. If this is directly related to the number of valence electrons an atom has, why do transition metals have variable valencies?
Transition metals have variable valencies because the energies of the 3d orbital and 4s orbitals (or similar orbital comparisons in lanthanides and actinides, etc.) are similar, so electrons are able to bond from the d-shell as well. Kind of similar to how some high atomic number elements are able to violate the octet rule, such as Xenon in xenon tetrafluoride or Sulfur in sulfur hexafluoride, because their 3d orbitals are able to participate in the valence bonding.
This effect also increases because the elements in the transition series also increases in the number of unpaired electrons, which increases the effect of the d-orbital.