I've never been asked that when the dog in question was still alive, but definitely when one has passed.
In my case, people know that I'm a dog person and pretty much figure that I'll be getting another one (hopefully not thinking that I want to "replace" the one who died but you know what I mean with regard to that word usage). I don't think anyone is deliberately saying something hurtful. The two I have now are to be our last dogs....I anticipate getting that question a lot...if I outlive them, that is.
There have been times when I've asked that question myself....in the case of someone who mentions that they just can't get themselves out the door to take walks just for themselves. "Have you thought about maybe getting another walking companion?" That kind of thing. Never really soon after they've lost a dog or if they don't give me a lead for asking the question.