In a statement, Nicholas Paolucci, a spokesman for the city's law department, said it was "disappointed" with the ruling and would consider its legal options.
"The city has a vital role in understanding the effect banks are having on the economic health of our neighborhoods," he said.
The Responsible Banking Act had called for an advisory board to review whether banks deserved to receive some of the city's deposits, based in part on how well they served low-income areas.
Read MoreHere's what's going on with the Dodd-Frank Act
Banks would have been required to provide documentation on efforts to modify loans for stressed borrowers, fund affordable housing and provide credit for small businesses, among other services.
Failla last year dismissed an earlier NYBA lawsuit, finding that the plaintiffs did not have standing because then Mayor Michael Bloomberg, whose veto was overridden by the City Council, was refusing to enforce the law.
But New York Mayor Bill de Blasio, Bloomberg's successor, has begun implementing the law. The current lawsuit was filed after the advisory board created by the statute submitted information requests to banks holding city deposits.
Read More Do we need to put drones on a tighter leash?
The city's lawyers had argued the law was simply intended to promote "transparency," but Failla agreed with the plaintiffs that it was an attempt to "advance policy objectives" by coercing banks' behavior, which infringed upon the federal and state governments' regulatory powers.
In a statement, NYBA President Michael Smith said: "This is an important decision for the banking industry with nationwide ramifications. The banks in New York will continue to be supervised by state and federal regulators, and will continue to reinvest in the communities in which they operate."
The case is The New York Bankers Association v. The City of New York, U.S. District Court, Southern District of New York, No. 15-cv-4001.