This sentence would be at least understandable if you change the word order and write like this:
子供に病院にいる友達に手紙を書かせた先生
It's because this sentence will be parsed like this (with "nesting"):
[子供に[病院にいる友達に手紙を書か]せた]先生
The "病院にいる友達に手紙を書く" part should be written as one verbal phrase because that's the action the child has to take.
This question is more or less similar: Multiple "wo"s in a sentence?
That said, it would be much better if you can avoid multiple に's like this. Multiple に both marking a person is hard for even native speakers to understand. The simplest way to fix this is using へ instead.
- 子供に病院にいる友達へ手紙を書かせた先生
- 子供に病院にいる友達への手紙を書かせた先生
- 病院にいる友達への手紙を子供に書かせた先生
(This is okay, as @優しいエイリアン suggested, because への modifies 手紙, and 病院にいる友達への手紙 is one noun phrase)
- [*] 病院にいる友達へ手紙を子供に書かせた先生 (wrong)
(Can you see why this is wrong? へ modifies the verb 書く. The "nest" structure will be broken if you write like this)
And I see nothing wrong with sentences like this:
- 子供に夜にお菓子を食べさせるのは良くない。
- 夜に子供にお菓子を食べさせるのは良くない。
- 夜にお菓子を子供に食べさせるのは良くない。
(uncommon word order, but perfectly makes sense)