@Brandon Turner
A number of people alluded to this, with the best explanation IMHO by @Brian Lucier, but let me add my two cents: there is zoning, and then there is the building code.
A "legal nonconforming" building is a building that was built legally (as per required permits and zoning) at the time of construction. If zoning for the area was later changed, for example from allowing triplexes to allowing SFH only, the building was grandfathered in. A new building on this lot can only be an SFH. But an existing triplex can stay, given a set of conditions (which likely vary by municipality, but mostly have to do with avoiding major upgrades, renovation of more than X% of the property, or the building being vacant/condemned for more than a certain period of time).
Adding a unit by putting up partitions/doors to subdivide an existing property in an unsafe way and without permits may be illegal under any zoning. The issue here is the safety/fire code more so than the zoning. It's best to stay away from this, except where a path to both meeting code and legalization may exist (for example, California's ADU legislation under which unpermitted garage conversions, units permitted as rec rooms, unpermitted additions, etc can become legal residential units once building code and some limited zoning requirements are met).
The tricky part is to understand when zoning and building codes interact, i.e. when required renovations to bring a property up to code trigger the loss of legal nonconforming status.