Your real estate agent should know the answer. It may vary around the country or jurisdiction but it most likely will fall on you to, the new owner to bring it up to code and permits. As said above it can be a real hassle. Florida and now most states require the seller to disclose any know issues or problems with the home. After the sale and a major problem arises, the seller could be financially liable but it may have to go to court.
But what happens if the seller moves out of state, you're probably stuck. You can check with the realtor that I believe certain amount of monies can be left in escrow of a certain period to cover such an event. Usually the local taxing district will re evaluate the home and for example, the property was listed as a four bedroom but the property records show only three, that is a red flag. Realities will always check the property records for the home description to list it. Now a days and in the past always use a realty. All states have laws and procedures to protect both the seller and the buyer. If this is more of a private sale, walk away unless you are paying cash and have money to do all repairs and upgrades needed.
Mortgage companies are very careful now a days after the housing crunch that started 15 years ago and it took about five or six years before the it settled down. Mortgage companies use property appraiser's that will do an outside inspection from the street and that it is not overpriced for the current market.
The four main area's of concern. HVAC, plumbing, electrical, and structure. If it's a room addition of any kind, it may have to be torn down. Electrical, could be dangerous. Electric problem can cause fire and injury. It would be needed to brought up to code if it is behind walls, the walls nave have to be opened. Same as for plumbing.