Some locality have city inspection before sales, so that illegality is discovered. Other localities don't deal with the violation until someone reports it. Sometime the county appraiser might visit and discover the violation.
In your case, since the conversion does not affect neighbors and if there is no , chances are the building department won't know about it.
2. How localities deal with violation
They usually work with the home owner to either address specific violation (too close to the road, or change out inadequate building material etc) to make the addition legal. Essentially the home owner can make the addition legal.
Only in rare situations the building department demand the addition to be torn down. The home owner has to be very uncooperative or the building is not safe.
3. Conclusion, you can buy a house with illegal converted garage, as long as:
(1) get familiarize with local law about inspection
(2) know how much money you need to make the garage "legal".
(3) know how easy it is to work with your local building department.
(4) ask the seller to lower the price accordingly.