The constituents of compound modifiers need not be adjectives; combinations of nouns, determiners, and other parts of speech are also common.
The former example contains only the bare adjective heavy to describe a device that is properly written as metal detector; the latter example contains the phrase heavy-metal, which is a compound noun that is ordinarily rendered as heavy metal absent an accompanying adjective.
Heavy is a bare adjective that modifies the compound noun metal detector.
Thus, heavy metal detector is a bare adjective + compound noun sequence.
Conventionally, and with the support of modern writing guides, compound modifiers that appear before a noun phrase should include a hyphen between each word, subject to certain exceptions.
Hyphens are used in this way to prevent confusion; without their use, a reader might interpret the words separately, rather than as a phrase.
Hyphens join the relevant words into a single idea, a compound adjective.