A compound noun can be one word, hyphenated, or multiple words. You can know the correct form only by looking it up and checking the part of speech.
...bookkeeper, roommate
...sister-in-law, aide-de-camp
...real estate, high school
Whatever the form, it must be maintained in all uses of the word.
...a bookkeeper problem
...an in-law problem
...a real estate problem
It is most important to note that, if the noun is separate words and is a direct adjective, it is NOT hyphenated. It is already a unit, and the original form is maintained.
...social security payment
...White House employee
...high school graduate
Happy punctuating!
Margie