As a referee (class 3, working my way up), I have encountered this situation before. I can offer a partial rationale for one situation, but even The Laws of the Game (Law 13, pg 42) merely states the rule and gives little insight.
For a direct free-kick taken by the defending team INSIDE the penalty area, the ball is only considered live and in-play after is passes beyond the penalty area. Therefore if the ball was kicked backward (and into the goal) from a position inside the area, it would technically never have gone into play. This is at least my interpretation. This happened in a game once in which I was ref and fortunately I knew the rule...unfortunately the opposing coach didn't and he gave me hell for not allowing the goal. The rationale for this case is the ball is not in play. However...
for the case where the defending team takes the kick OUTSIDE of the penalty area, and scores directly, no rationale is listed (as far as I have read). So now I'm curious. I will ask my head referee when we meet and hopefully he can explain as far as a rationale is concerned. Meanwhile, it would be interesting to hear any fellow refs to weigh in on this.