If the structure is illegal, it is illegal. It either neither needs to be removed or brought within the code requirements. The buyer may have some sort of failure to disclose claim against the seller, the broker or the agent or some combination of the three.
Consult with a local real estate attorney.
There is nothing that can be done to avoid the city's correction order. Contact the city to work out some way to correct or remove the violation before it goes to further enforcement or conviction.