If it makes you feel any better, similar rules exist in English. An indirect object precedes an direct object if they're both nouns and 'to' is not used: "I'm giving the dog a bone." If 'to' is used the the indirect object comes first, and you'd always use 'to' if there are pronouns: "I'm giving a bone to the dog." "I'm giving it to him". You wouldn't say "I'm giving him it." Actually the word order is similar to English if you think about it; English is a Germanic language after all. The big difference is that in German you use case endings to tell what is being given and what is receiving; in English you have to use a preposition. Because German uses case endings, word order is more flexible, and the rule given is more the "default" word order than the required word order. Grammar books don't usually mention that kind of thing because it's easier for learners to just follow some relatively simple rules rather than try to grasp the complex interplay of emphases and custom which a native speaker uses to arrive at a word order used in a given sentence.
If you explain it out as a set of "rules" then it does seem unnecessarily complex and confusing, but native speakers just know the correct word order by intuition without having to think about it. The point of grammar is so you can learn what is correct without going through time consuming process of trial and error that you went through as a 1 year old; young children basically spend their entire day learning language, so they don't seem to mind trial and error. With enough practice you can probably gain an "intuitive feel" for correct word order as well, but it does take practice.
Anyway, I'm pretty sure that for the purposes of a person learning German it's better to just accept that the rule "just exists". I'm sure that an expert in the history of German could give you a more detailed historical reason, but my feeling is that learning another language is difficult enough without trying to learn the entire evolution from prehistoric roots.