Solution 1:

Yes, this is grammatical. The first noun is acting like an adjective. As Colin notes, you can't always put a noun in a the same position as an adjective bu it does work as 'N N'.

'Cheese casserole' isn't a casserole that happens to have a lot of cheese (which is what is implied by 'cheesy casserole'); somehow 'cheese ' is essential to the casserole that is a 'cheese casserole'.

The official term for this usage of a noun as a modifier is Noun Adjunct.

It is not an Adjectival Noun which is the other direction, an adjective that acts like a noun.

Solution 2:

The two nouns "repetition compulsion" mean "a compulsion for repetition" — and as such they are easily understood by native speakers.

It can be argued that the first noun in such pairs functions as an adjective. But the distinction is not always clearcut.

I hung my jacket on the coat rack.

Is coat an adjective or a noun there?

Edit: @Kosmonaut and I have discussed this very issue in chat. He (a grad student in linguistics) gave "poster board" and "hat rack" as legitimate noun-noun combinations.

Solution 3:

Robusto does a good job of responding to the NYT sentence. Here are some other ways to end a sentence with two nouns:

I like Robert; John.

This is a car — truck!

This is a house (mansion).

Most of these are borderline with regards to acceptance. You will hear from time to time but the point is that messing with punctuation can result in some oddities. The first in the list is most common in headlines: "Farmers slaughter cows, chickens."