This isn't much of an answer, but: the recent California law changes dealing with ADUs are new and their interaction with local law (building codes, etc.) is complex. The ramifications of the changes have yet to be fully fleshed out in practice. A lot can depend on the extent to which individual cities and counties embrace the new laws and try to encourage ADUs versus resisting the laws and trying to restrict ADUs as much as the state law will allow them to do so. It will also likely depend on "how illegal" the unit is. If it is up to code in terms of the actual construction and was only illegal due to zoning (i.e., too many units on the property), that's one thing, but if the construction itself has issues (i.e., it's not built to safety standards for habitable space) that could be much more of an obstacle.
You'd be well advised to seek out someone with expertise in local real estate matters (e.g., an attorney, a real estate appraiser, or some kind of planning/permitting consultant if you can find one you trust) who can give you an accurate sense of the situation in your area. Or, even easier, just tell the seller you're not going to buy the property with these legal encumbrances and they'll have to legalize it themselves or you'll just walk away from the deal.