Options and Trade-offs
Each of the three paths resolves the violation differently, and each one gives something up.
Legalize the unit. This path runs through the local building department. The owner pulls permits, brings the unit up to current building and zoning codes, and seeks a certificate of occupancy. Not every unit can be legalized; zoning, setbacks and lot coverage can rule it out. California law on accessory dwelling units has opened a path for some units, and the local building department can say what applies to a given parcel. No permit is assured.
Remove or stop using the unit. The owner stops renting the space, restores it to its permitted use, and closes the code enforcement case. The rental income ends, and the restoration may need its own permits.
Sell in the present condition. A buyer who takes the property as it is takes on the compliance work and the risk. A direct or cash offer in that setting is often lower than an open-market price, because that buyer absorbs the repairs, the permitting and the cost of reselling. In exchange, the seller gets less preparation, fewer showings and less dependence on a buyer's loan. The city's enforcement authority and the seller's disclosure duties stay the same. Listing with a real estate agent, with or without correction first, is another version of this path. The guide to selling as-is covers it in more detail.
Comparing written offers and estimated net proceeds (the price less commissions, repairs, carrying costs, loan payoffs and closing costs) makes the differences between the paths concrete. The guide on correcting or selling sets them side by side. Which path fits depends on the specific violation, the local rules and the property's condition.