Because the latter have dimensions! The Gravitational constant, G, appears in F= -GmM/r^2. In the metric system (mks), r has units of meters, both m and M have units of kg so that "mM/r^2" have units of [itex]kg^2/m^2[/itex]. F, a force, has units of "[itex]kg m^2/sec^2[/itex]". In order to make the units on both sides of the equation the same, G must have units of [itex]1/(kg sec^2)[/itex].
Avogadro's number is the number of molecules per mole. The number of molecules does not depend on any units so Avogadro's number has units of [itex]mol^{-1}[/itex].
Plank's constant is the "h" in [itex]h\nu[/itex] where E is energy, and so has units of [itex]kg m^2/sec^2[/itex] while [itex]\nu[/itex], a frequency, is "number of cycles per second". "Number of cycles", like "number of molecules" is just a number without units. Since we need to have left "[itex]kg m^2/sec^2[/itex]" we need . That means that h must have units of [itex]kg m^2[/itex] in the numerator and one "sec" in the denominator: [itex]kg m^2/sec[/itex].