The correct order can be remembered by the acronym RID (as in, "I need to get RID of this confusion about pronouns!") for reflexive, indirect, direct.
All three pronouns can't appear together, but two can in the following combinations:
- Reflexive-Indirect: Se me olvidó. ("I forgot." or literally "It forgot itself to me.")
- Reflexive-Direct: Me lo pongo. ("I put it on.")
- Indirect-Direct: Me lo dio. ("He gave it to me.")
Also remember the la-la rule: if both pronouns start with the letter l, change the first pronoun to se.
As to why it is how it is, I wasn't able to find anything. This is most likely part of the natural evolution of a language over time, as opposed to an instance of grammarians sitting down and deciding on a rule.