That is a pretty broad topic jp. It depends on the situation. I know of people who bought a 4-plex that the city tried to force them to restore to a duplex. They told me that they got a Lawyer and it is allowed to stand until they sell it or pull another permit.That hurts. It has four units on a 60amp main!
A friend/client of mine bought an illegal 2 on 1 with an open code case, really cheaply,tore down the illegal unit increasing the back yard size and “flipped” the property for a decent profit. The neighbors love flippers in these cases.
Framing,electrical, plumbing,items like this are a non-issue IMO.