It nominalizes the phrase 'να κοιμάσαι". Without the definite article, it would sound incomplete (contrary to English, where the gerund 'sleeping' does not require an article).
This sentence is an example of gerund in English. Most of the sentences in this "Gerund" section are not. Some people confuse gerunds and present participles because the form is identical. https://www.englishgrammar.org/gerund-present-participle/
Can one say "Το να κοιμάται είναι καλό"? What about the other forms of the verb κοιμάται?
Το να κοιμάται είναι καλό would mean "It's good that he is sleeping".
You could use other forms of the verb κοιμάμαι (the citation form is usually the first person singular present indicative, i.e. the "I" form not the "he" form) but it would indicate that the action is performed by that person.
Το να κοιμάσαι είναι καλό could also mean specifically "It's good that you sleep" but, as in English, you can also use this generically: "It's good to sleep" (regardless of who does the sleeping -- "you" as in "anyone" rather than "you" as in "the person I am talking to right now".)
Ευχαριστώ πολύ για την απάντηση!
Yeah, it was a mistake on my part to say κοιμάται to mean the verb citation form of κοιμάμαι.
By the way, this means that Greek is more flexible than English in such constructions!