The reason being, you are looking for the enthalpy of FORMATION of DIAMOND.
So when you apply Hess' Law, the second equation MUST be flipped so you get this equation...remember when you reverse the reaction, you must change the sign of the enthalpy (H).
CO2(gas) -> C(diamond) + O2(gas) , H=+395.4 kJ/mol
Then you retain your graphite equation and add these two equations together.
C(graphite) + O2(g) -> CO2 (g) , H = -393.5 kJ/mol
CO2(g) -> C(diamond) + O2(g) , H = +395.4 kJ/mol
The end result when you add these two together is this equation...note that the CO2 and O2 gas drops out of the equation:
C(graphite) --> C(diamond) , H = -393.5 + 395.4 = +1.9 KJ/mol
Remember, you flipped the second equation and not the first because you wanted to FORM , i.e. you are looking for the enthalpy of FORMATION, of C(diamond)