dangling participles principle correction
The problem with dangling participles comes when we read the participial phrase and connect it to the subject, but for whatever reason the true subject of the sentence has been omitted and we end up connecting it to the object instead.
In the case of your specific sample sentence, it looks like dangling participles are writing carefully, which is obviously nonsense as they're an abstract concept and are incapable of performing actions. This can be fixed by specifying the subject, either converting it to active form or keeping it passive:
Writing carefully, dangling participles should be avoided by you.
or
Writing carefully, you should avoid dangling participles.
There's another issue with this sample sentence that isn't related to your question, but I'll point it out anyway. The participial phrase "Writing carefully" implies ongoing action and isn't a good fit for the clause with which you've followed it. I would use it, for example, when saying something like
Writing carefully, I penned my memoirs.
For a clause like the one you've used, I would use something like "When writing carefully," instead:
When writing carefully, you should avoid dangling participles.
A participle is "dangling" when the intended grammatical subject of the participle phrase is not the subject of the main part of a sentence. This means that, read as strictly as written, the participle takes a different subject (normally the subject of the main clause). Interpreted in that way, such a sentence will doubtless mean something different to that intended.
Take your example.
"Writing carefully, dangling participles should be avoided."
The grammar tells us that the subject of "writing" takes the same subject as "should be", which is "dangling participles". So the sentence strictly means something like:
"When dangling participles are writing, they should be avoided."
Of course this is nonsense.
In many examples of this it will nevertheless be possible to infer what the writer means. However such sentences will likely be confusing to read as it will not be clear what the subject of the participle is, making the reader have to think more than necessary in order to decipher the writer's intended meaning.