Co2 is a greenhouse gas. it traps the sun's heat and does not let it escape from the earth's surface.
during the day the sun's radiations warm the earth, and at night some heat escapes out of earth's surface,while some is trapped by the gases like co2. this helps in maintaing normal temperature at night also.
if the amount of co2 in atmosphere increases, then it will trap more heat, which leads to global warming.