Here we present a detailed investigation of the Co and Ir local electronic structures in ${\mathrm{La}}_{1.5}{A}_{0.5}{\mathrm{CoIrO}}_{6}$ ($A=\mathrm{Ba}$, Ca) compounds in order to unravel the orbital hybridization mechanism in these CoIr-based double perovskites. Our results of x-ray powder diffraction, ac and dc magnetization, Co and Ir ${L}_{2,3}$-edge and Co $K$-edge x-ray absorption spectroscopy and x-ray magnetic circular dichroism suggest a competition between magnetic interactions. A dominant antiferromagnetic coupling is found to be responsible for the ferrimagnetic behavior observed for $A=\mathrm{Ca}$ below $\ensuremath{\sim}96\phantom{\rule{0.16em}{0ex}}\mathrm{K}$, the competing magnetic phases, and the cationic disorder in this compound giving rise to a spin-glass state at low temperatures. For the $A=\mathrm{Ba}$, on the other hand, there is no evidence of long-range order down to its spin-glass transition temperature. The remarkably different magnetic properties observed between these two compounds are discussed in terms of the structural distortion that alters the strength of the Co-Ir couplings, with a relevant role played by the Co $3d\phantom{\rule{4pt}{0ex}}{e}_{g}--\mathrm{Ir} 5d\phantom{\rule{4pt}{0ex}}{j}_{\mathrm{eff}}=1/2$ hybridization.