We perform a thorough first-principles study on superconductivity in yttrium carbide halide Y$_2$$X_2$C$_2$ ($X$=Cl, Br, I) whose maximum transition temperature ($T_{rm c}$) amounts to $sim$10 K. A detailed analysis on the optimized crystal structures reveals that the Y$_2$C$_2$ blocks are compressed uniaxially upon the halogen substitution from Cl, Br to I, contrary to the monotonic expansion of the lattice vectors. With a nonempirical method based on the density functional theory for superconductors within the conventional phonon mechanism, we successfully reproduce the halogen dependence of $T_{rm c}$. Anomalously enhanced coupling of one C$_2$ libration mode is observed in Y$_2$I$_2$C$_2$, which imply possible departure from the conventional pairing picture. Utilizing the Wannier representation of the electron-phonon coupling, we show that the halogen electronic orbitals and ionic vibrations scarcely contribute to the superconducting pairing. The halogen dependence of this system is hence an indirect effect of the halogen ions through the uniaxial compressive force on the superconducting Y$_2$C$_2$ blocks. We thus establish a quantitatively reliable picture of the superconducting physics of this system, extracting a unique effect of the atomic substitution which is potentially applicable to other superconductors.