You are referring to a "dangling modifier" (a species of "misplaced modifier") and yes, many writers, teachers, and grammar books tell us it is an error. But it is not a grammatical error. I mean this in the sense that what we have been taught to think about "dangling modifiers" does not depend on grammatical issues like syntax and inflexion. Rather, the question is semantic ambiguity. We ask whether things mean what we intend for them to mean. That's a different matter entirely.
We are taught in school that the implied subject of a participial phrase is usually the nearest noun phrase, particularly if it is the grammatical subject of the adjacent clause.
But there is no grammatical reason for thinking so. We believe it because someone told us. Or, if we did not pay attention in school, we don't believe it and do not care and the issue almost never creates any confusion at all.
We find a similar relationship with pronouns and their referents. We are often taught in school that the referent of a pronoun is the nearest noun phrase, especially the nearest noun phrase to the left of the pronoun. But a simple comparison shows that this is not the case.
I cannot fit the trombone into the suitcase because it is too big.
I cannot fit the trombone into the suitcase because it is too small.
Notice that both sentences are constructed exactly the same. But the referent of the pronoun it in Sentence 1 is trombone, while the referent in Sentence 2 is suitcase. Clearly, the grammar is not sufficient to help us understand the meaning of each pronoun. We must look to the larger context—not simply to the meaning of big and small but also to our understanding of the way that suitcases work.
We are accustomed to working out semantic relationships like this unconsciously.
So it is with participial modifiers. A reader would have to be pretty obtuse not to understand the meaning of the childless sentence. In an expression such as it was his desire, the pronoun it can have no referent at all (we call it a "dummy subject"), so we understand that it cannot refer to something childless. The pronoun his and the surrounding context make the intended meaning clear enough.
Native speakers are never confused by sentences like this. In fact, you'd have to explain it in a lot of detail to make most native speakers understand why you thought there was an error in the first place.
The other example is slightly different. Taken out of context, it is somewhat amusing. "Ho ho," one thinks. "You've called the dog a stick!" Books about grammar and style love to use sentences like this as examples of "bad grammar."
But if we look at the larger context, we can see why the author did not see a problem, and why his editors did not see one either:
“And the dog?”
“Has been in the habit of carrying this stick behind his master. Being a heavy stick the dog has held it tightly by the middle . . ."
Obviously, the dog is not a stick. The dog is holding the stick, and the stick is heavy. You and I belong to a very small circle of people who notice this sort of thing. The rest of the world does not bat an eye.
To sum all of this up:
A so-called "dangling participle" is not a grammatical error. It is a label we give to a participial phrase that refers to a topic that is not where our grammar teachers told us to expect it.
In reality, listeners and readers are almost never confused by a "dangling participle." The context almost always makes the meaning clear, much as context almost always makes clear the exact meaning of a pronoun.
If your writing is being graded by a very strict instructor, you should probably take care not to write a "dangling participle." Although teachers are quite happy believing that the meaning of a pronoun depends on factors that go beyond its position in a sentence, they often make no such allowance for a participial phrase.
In any case, you should always watch out for genuine ambiguities.
If someone points out a "dangling participle" in your speech, you should bite them or hit them with a stick.