A couple of years ago I had an assignment (which I posted about) where the subject was originally a 2-unit property and had been converted to a 4-unit property.  As a 2-unit property, the subject was grandfathered because of the sub-standard lot size.  If damaged, destroyed, it could be rebuilt to 2-units.  If vacant, it could only support a single-unit.  As a 4-unit property, it was an illegal use.  The zoning wouldn't allow it and, in this case (as I checked with the zoning officials) there was no way a variance would be issued.
Pretty simple:  It could never be a 4-unit under current zoning and a variance would not be issued to allow a 4-unit improvement.  An illegal use.
This property was renovated throughout and was collecting rents on all four units.  The city this property was located in has rent control; even though two renters were in the illegal units, they now had certain rights.  In the case where a renter has rights and is renting an illegal unit, the landlord can evict them but has to pay a relocation fee.
The city stated that if someone complained, they would take action.  This is evidence of active enforcement IMO.
Market value requires that the subject be valued at its H&BU.  As-is, it was an illegal 4-unit property; per zoning, it should be a duplex.  
In the valuation analysis, not only did the additional rents not come into the equation, but the cost to reconvert to the legal use + relocation costs for the two tenants in the illegal units were part of the equation (and, as always, Ei).
The property's market value is as-it-should-be (a legal 2-unit property) less the costs to return it to that state.  As JGrant notes, a prudent buyer, being well informed and advised, would identify the illegality and act... prudently.  While any specific buyer may not make any deductions or change anything, a prudent buyer would.
Illegal uses are those that cannot exist.  There is no provision for them to exist and there is no exception for them to exist.  Illegal uses may trade at a premium to market value for whatever reason, but in a market value assignment, legal uses are one of the fundamental components of the H&BU analysis (along with physically possible, financially feasible, and maximally productive).
As always, I make a significant distinction between a "legal use" and a change or alteration that is permissible but not permitted.
In my case, 2-units only were the maximum density allowed for my subject and it had 4-units.  This impacted value (negatively).  If permits could be obtained, then it would have been a legal use with an alteration that required permits; that may or may not impact value.
In my case, it was an illegal use that would never be allowed.  That did impact value.
I completed the report (after conferring with the client).  It was an as-is appraisal.  I reported that the current use was illegal (checked the box and described my research and summarized my analysis).  I provided an as-is value that considered the impact of the illegality.  The value opined was market value.
I appraise in San Francisco.  San Francisco has a number of different residential zoning ordinances.
One residential ordinance does not allow for second units. Another does.  Looking at the houses from the street, one might not know where one zoning ends and another begins.
In San Francisco, it is very common to have the garage and storage space on the ground level and original living area on the 2nd level.  In San Francisco, it is very common that owners of these properties have finished off the storage space to create finished living area.  Sometimes they are directly connected to the 2nd level via a stairway, sometimes one has to go through the garage to get to them.
Many of them have been finished as a accessory unit.  
In the zoning that allows for a 2nd unit, the lack of permits is not significant, although many real estate agents advise their sellers to get the permits prior to selling.  Getting a permit isn't that onerous and San Francisco has an amnesty program available to get after-the-fact permits.  These spaces (2nd unit or finished space) have value in the market with or without permits in the case where the zoning allows it.
In the zoning that doesn't allow for a 2nd unit, the city will come in and require the owner to remove the kitchen and bath.  And, I mean "remove"; not just take out the appliances.  In this zoning, those illegal units can have an adverse impact on value (neutral at best).  It isn't uncommon to see an MLS listing state "illegal unit has been removed".