Because it's the accusative case (taught in later skills). It's short for "I wish you a good night", where "dobrá noc" is an object, hence "dobrou noc".
This is not visible in e.g. "dobrý den" as masculine inanimate looks the same in accusative as in nominative.
You seem to be learning German, so: it's the same principle as why "Guten Tag" has an "-n" ending on "guten".