Supreme Court Justices do not miraculously know everything about every possible topic and Scalia does not know everything about guns and the original meaning of the Second Amendment.
To a large degree, Supreme Court Justices use information from prior cases and decisions and the briefs submitted for particular cases. Scalia and the other Justices have a good deal of information that was critical to the questions posed by Heller and McDonald. But the questions posed in those cases did not cover the totality of Second Amendment history or meaning. As other case come before the Court, the Justices will get additional information to help them decide the specific questions of those cases. The Second Amendment is far from fully defined in the judicial system.