They can only do that if it's an illegal unit, which is not exactly a secret from the renter when they first moved in.
Now, if there was a way a tenant could make a legal unit into an illegal unit and then invoke this, I could see that as a problem.
Actually, a prospective tenant probably has no idea if the unit is "illegal" or not. It is an apartment for rent and there is a line going out the door, so don't ask any annoying questions.
I can understand the confusion because I once interned for a midwestern city's planning department. There if someone built an unapproved apartment above their garage, the city would hit them like a ton of bricks.
In San Francisco, it is not like that, and these so-called "illegal" units are enshrined by law and practice in many respects. As a tenant, you have nearly all the same rights as a legal unit, so this would probably not figure into your evaluation.
What would make even more sense is very severe fines to the landlord for renting illegal units. Something like a multiple of all the rent they have ever collected on it.