Use "medium-term" when acting as an adjective before a noun, and "medium term" otherwise.
When acting as an adjective before a noun, you should hyphenate it: "medium-term." Why? The hyphen serves to make clear that the two words are acting jointly as a single adjective.
James has a medium-term investment strategy.
James has a medium term investment strategy.
We generally omit the hyphen when using it as a noun or as a predicate adjective after a verb.
Alice's investments are for the medium term.
Alice's investments are for the medium-term.
When serving as an introductory phrase, the hyphen is omitted as well.
In the medium term, our focus will be on expanding our customer base and improving product quality.
Use "medium-term" when used as an adjective before a noun, and "medium term" otherwise.
Remember, although it's not strictly incorrect to omit the hyphen, using a hyphen in "medium-term" is generally recommended when the term functions as an adjective before a noun. This is also a widely accepted convention.
The company has medium-term growth prospects.
Her medium-term goals include learning a new language.