why does carbon has valency 2 sometimes
The valency of carbon is usually 4 as in CO2, CH4 etc. Yes sometimes it has valency 2, as in CO, where the C is 2, and rarely 3 as in C2O3.