Appraisers toss around the word illegal far too casually. Imo, the only time illegal affects HBU is at the point where it is truly illegal for zoning to the point where city can come in and force removal or police powers can come in and seize property. Yes, the HBU for many homes would be a drug lab as far as maximally productive, only problem is, DEA can come in and seize the home and arrest the owner (even if they rent it out and had no idea tenants were using it as a drug lab). A property built out to lot line boundaries or used for commercial in residential zoning is illegal to the point where it is visible or a hazard and neighbors would complain and zoning authorities will fine the owner and/or demand removal. Those properties would need the adverse illegal conditions disclosed and affect on market value and HBU discussed.
Anything else, such as lack of permits, shoddy construction, interior improvement such as putting in a second kitchen might not meet lender guidelines, and be a cause for denying a loan ( or curing the defect, subject to).
A lender has 100% right to deny a loan or demand an owner repair in order to fund. However, lender demands and market value as to what market recognizes and will pay are two different elements. Which is why Fannie and FHA recognize, with certain guidelines, that non permitted and even "illegal" property uses, such as garages converted or non permitted additions, as long as they are functional and safe for occupancy, can have value in market and that value can be reflected in report, as long as it is typical for area and appraiser provides comps with same level of non permitted uses to show market acceptance.