Dipyridyl molecular junctions often show intriguing conductance switching behaviors with mechanical modulations, but the mechanisms are still not completely revealed. By applying the ab initio-based adiabatic simulation method, the configuration evolution and electron transport properties of dipyridyl molecular junctions in stretching and compressing processes are systematically investigated. The numerical results reveal that the dipyridyl molecular junctions tend to form specific contact configurations during formation processes. In small electrode gaps, the pyridyls almost vertically adsorb on the second Au layers of the tip electrodes by pushing the top Au atoms aside. These specific contact configurations result in stronger molecule-electrode couplings and larger electronic incident cross-sectional areas, which consequently lead to large breaking forces and high conductance. On further elongating the molecular junctions, the pyridyls shift to the top Au atoms of the tip electrodes. The additional scattering of the top Au atoms dramatically decreases the conductance and switches the molecular junctions to the lower conductive states. Perfect cyclical conductance switches are obtained as observed in the experiments by repeatedly stretching and compressing the molecular junctions. The O atom in the side-group tends to hinder the pyridyl from adsorbing on the second Au layer and further inhibits the conductance switch of the dipyridyl molecular junction.