It's just how scientists define it.
6.022x1023 amu = 1g.
Oxygen's atomic mass is 16 amu.
The definition of molar mass/gram atomic mass is the mass of one mole of atoms.
1 mol of O = 6.022x1023 atoms.
Therefore, 6.022x1023 atoms O * (1 gram/6.022x1023 amu ) = 16 grams/mol. This is how atomic mass can equal molar mass.