It may in certain instances be a legitimate question (for instance if the doctor thinks the patient might be a risk to harm himself or others), or it could be part of a research project that the physician or his / her office is involved in. During residency I was involved in a large project looking at gunshot wounds in one of the highest crime rate areas of the country. The aim of the project was to determine if the site of the wound was more important than the caliber of the gun. The data collected from that project over a 4 year period became a hallmark of ballistics research in forensic medicine. Despite the fact that much of the outcome was common sense it disproved several theories about firearms. In the study we had several outliers for instance such as two kids who were killed with pellet guns. Pellet guns are almost considered toys by many, and I can remember as a kid being in BB gun wars where we would shoot at each other.
The research also showed that about 88% of all the GSW involved young males, the majority of which were black, despite the fact that they only made up about 33% of the documented census for that region. Men were much more likely to use a gun for suicide than a woman (although we did have one case), and a large percentage of the guns which were used in street shootings tended to be stolen.
I do know the Academy of Pediatrics has had some interest in the percentage of people who have both children and guns in their home, so this could (possibly) have been such a project. In any case, it is perfectly acceptable to say that you decline to answer the question.