There are lots of confusing rules around hyphens, I found the following at grammarbook.com I thought it was a great way to explain it.
Most usually you hyphenate two or more words when they come before a noun they modify and act as a single idea. This is called a compound adjective.
Examples:
an off-campus apartment
state-of-the-art design
When a compound adjective follows a noun, a hyphen is usually not necessary.
Example: The apartment is off campus.
However, some established compound adjectives are always hyphenated. Double-check with a dictionary or online.
Example: The design is state-of-the-art.