I think people ask this question because they try to gauge how excited you are, and, in turn, can express either their own excitement or put on a more unbiased, supportive face. I really feel that people do this without thinking about it most of the time.
One of my best friends told me that not that long ago that she was pregnant, and I didn't know how to respond. I didn't ask the question, "Was it planned?" but I did say, "Oh wow! Congratulations! How do you feel?"
....She ended up having an abortion and never wanted the fetus to begin with. I'm sure if I would have asked, "Was it planned?" She would have said no, and that she wasn't going to keep the baby instead of me being how I thought I should be.