In addition to Janka's and Tofro's answers:
I think a good criterion to decide whether a hyphen should be used to structure overly long compounds would be if the word is in common use (in the specific audience). E.g.
Bundesausbildungsförderungsgesetz
is clearly in common use (in those parts of society who use the word at all), and pronunciation is usually very "smooth", with no dicernible stop or pause.
On the other hand
Investitionsstaatssekretär
is neither in common use (even not in the ministry where this person resides, I suppose); the official job title would rather be Staatssekretär im Bereich Investitionen, Blablabla und Blablablabla, and journalists made that word up ad hoc in order to have a more or less practical name for the guy. In such a case
Investitions-Staatssekretär
may be considered a good idea as it helps the reader's eye to quickly recognize the parts of the compound.
As everybody knows, reading is not decoding words letter by letter. Reading is recognizing words by their overall "face" (or gestalt if you like). Therefore, in unusual compounds, a hyphen may be helpful.
On the other hand, hyphens should be avoided in words that are known (by the audience in question) because in such words they add an unnecessary stop.
Hamster-Käfig
is not a good way to write that word. Every child knows a Hamsterkäfig and is used to the word (or should be used to it). However
Hamsterkäfig-Reparaturanleitung
is wisely spelled with a hyphen because
Hamsterkäfigreparaturanleitung
although technically possible is not a word that is in common use even in hamster-breeding parts of society, and deciphering it will take unnecessary effort by the reader that can he be spared of when the better-known parts of the compound are separated by a hyphen.
Conclusion: you need very good knowledge of common use of the language, and also of your audience, in order to take good decisions on zusammenschreibing or getrenntschreibing of these words.