Relationship between phonons and thermal expansion in Zn(CN)2 and Ni(CN)2 from inelastic neutron scattering and ab initio calculations