The differences in molecular mass stem from two sources:
Nuclear binding energy
The definition of the atomic mass unit and Avogadro's number (and thus the g/mol), is the mass of one atom of the carbon-12 isotope $\ce{^{12}_6 C}$. 1 amu = $\frac{1}{12}$ the mass of one atom of $\ce{^{12}_6 C}$ and the g/mol unit is based on the definition of Avogadro's Number, which is the number of $\ce{^{12}_6 C}$ atoms in 12 grams of $\ce{^{12}_6 C}$.
Because of the differences in binding energies in the various nuclei, the monoisotopic mass of individual isotopes are not integers. For example, the mass of $\ce{^{16}_8 O}$ is 15.99491463 amu (and not 16). The monoisotopic masses of the most common isotopes of oxygen, nitrogen, and carbon is shown below:
mass number % absundance isotope mass
Carbon 12 98.930 12 (defined)
Nitrogen 14 99.632 14.003074
Oxygen 16 99.757 15.99491463
Isotopes
Generally, molecular masses (unless otherwise specified) are average molecular masses composed of average molecular masses of the elements based on their isotopes. For example, even though the most common isotope of carbon has a mass defined as 12 amu, there is another naturally occurring isotope $\ce{^{13}_6 C}$ with 1.07% natural abundance, leading to carbon having a non-integer average atomic mass of 12.01 (to 4 significant figures). There are two isotopes of nitrogen, and three isotopes of oxygen.
Average atomic mass
Carbon 12.011
Nitrogen 14.007
Oxygen 15.999
Thus, $\ce{CO}$ has a molecular mass of $12.011 + 15.999 = 28.010$ and $\ce{N2}$ has a molecular mass of $14.007+14.007=28.014$. Even their monoisotopic masses are different:
average molecular mass monoisotopic mass
dinitrogen 28.014 28.006148
carbon monoxide 28.010 27.99491463