People say this when someone asks a question that's a little difficult to answer. Saying "That's a good question" gives you a little more time to think of your response.
For example, if someone asks you a question at work that you haven't thought about before and don't have an answer for, respond this way:
That's a good question. Let me find out for you.
Of course, you can also respond with "That's a good question" if someone asks a question that's really interesting and intelligent. But to be clear, it might be better to use a slightly different phrase like:
That's an excellent question!