Because "Bonan nokton" is a short form of "Mi deziras al vi bonan nokton." (I wish you a good night.) Therefore you need the accusative form. Same for "Bonan tagon", "Bonan matenon", etc. but also for "Saluton." "Dankon." "Pardonon."
Do speakers ever shorten these greetings informally? Like saying, "Bon' Nokton" You still have the accusative on nokton, and the cut off 'an in Bonan could be understood through context. Just wondering.
is this phrase a parting phrase or a greeting phrase? In english, "good morning/afternoon/evening" is a greeting phrase but "good night" is solely a parting phrase. Does Esperanto make that distinction?