A federal judge ruled that the Pentagon’s restrictions on news outlets violated the First Amendment, in a lawsuit brought by The New York Times.