The judge may ask, but it doesn't really matter. The court won't enforce an illegal contract, so the court won't grant a landlord a money judgment for rent arrears owed for an illegal apartment.
That's why there are professional tenants - people who know how to game the system and get away with paying rent.
"It is the opinion of this court that when a town ordinance prescribes a certain residence as illegal, it is the job of the court to enforce the town's wishes. Furthermore, a landlord should not benefit from her willful misconduct of violating local zoning ordinances. Therefore, a landlord should be proscribed from recovering rent on a residence known to be in violation of local zoning ordinances."
That's from the case Cater v. Saunders, decided by Judge Fairgrieve in 2002. He is still the landlord/tenant judge in the Nassau County District Court.
And someone stated that the landlord could just not give the tenant their deposit back - that would probably be a violation of the law, General Obligations Law § 7-103, a deposit remains the property of the depositing party.
Again, it's tough to say, which is why I stand by my suggestion that OP contact an attorney so that OP can give the attorney all of the facts specific to OP's case and the law can be applied properly. Either way, good luck OP.