US supreme court justice Sonia Sotomayor has said the court is likely to have to rule on the issue of balancing national security and freedom of speech due to WikiLeaks posting a cache of US military records about the Afghan war.

Sotomayor said the incident, which has been condemned by the Pentagon, was likely to provoke legislation in Congress that would require judicial scrutiny.

Her comments came in response to a question about security and free speech by a student at Denver university. The judge said she could not answer because "that question is very likely to come before me". She said the "incident, and others, are going to provoke legislation that's already being discussed in Congress, and so some of it is going to come up before [the supreme court]".

WikiLeaks posted more than 76,900 records of incidents and intelligence reports about the Afghan war on its website last month, providing a devastating portrait of the war. They revealed how coalition forces have killed hundreds of civilians in unreported incidents and how Nato commanders fear neighbouring Pakistan and Iran are fuelling the insurgency.

The publication of the files, which were made available to the Guardian, the New York Times and the German weekly Der Spiegel, was one of the biggest leaks in US military history. The Pentagon has said the leak put the lives of US service personnel and Afghan informants at risk – a charge WikiLeaks denies.

Sotomayor said the balance between national security and free speech is "a constant struggle in this society, between our security needs and our first amendment rights, and one that has existed throughout our history."

Sotomayor compared the issue with the debate over allowing publication of the Pentagon Papers, a secret study about the Vietnam war. The New York Times published those in 1971 after the supreme court declined to block their publication over the objections of the Pentagon.

"That was not the beginning of that question, but an issue that keeps arising from generation to generation, of how far we will permit government restriction on freedom of speech in favor of protection of the country," Sotomayor said. "There's no black-and-white line."