The tenant will not live in the apartment when the apartment is subleased. The tenant retains a superior right to ultimate possession in relation to the subtenant. The tenant must have a basis to commence the lawsuit. If the tenant claims a right to sue because the sublease ended or because the sublease is terminated due to some uncorrected default, the tenant may be allowed to claim a ground for maintenance of a summary proceeding. The "right" to bring the proceeding does not mean that the tenant will surely win. Every case proceeds along in it own manner.
If the "illegal" sublease is in a rent regulated apartment and if the prime tenant charged an "illegal" rent to the subtenant, then the subtenant may assert a defense to that lawsuit based upon the tenant's violation of the Rent Stabilization Code in charging an "illegal" rent.
If you are the subtenant and you are looking to stop the tenant, you may succeed, if you have valid defense and are able to properly present the defense in court. But the success may prove an "illusion" as beating the tenant does not necessarily provide the subtenant to a stronger right to possession of the premises than the tenant and does not ordinarily transfer the tenant's rights to possession in relation to the landlord.
If the apartment is rent stabilized, and the tenant never lived in the apartment, and the tenant has habitually sublet the apartment without interference from the landlord, then the tenant may be an illusory tenant and that creates another method for defeating the tenant and also for taking the tenant's place as the legitimate tenant in the apartment.
So the best course of action is to consult with an attorney and discover whether there is a method to avoid eviction if sued by the prime tenant.
The answer provided to you is in the nature of general information. The general proposition being that you should try to avoid a bad outcome if you can.