'Wide berth' is most commonly found in the phrases 'keep a wide berth of', 'give a wide berth to' etc. It was originally a nautical term. We now think of a ship's berth as the place where the ship is moored. Before that though it meant 'a place where there is sea room to moor a ship'. This derives in turn from the probable derivation of the word berth, i.e. 'bearing off'. When sailors were warned to keep a wide bearing off something they were being told to make sure to maintain enough sea room from it.
Like many seafaring terms it dates back to the heyday of sail, the 17th century. An early use comes from the redoubtable Captain John Smith in Accidental Young Seamen, 1626:
"Watch bee vigilant to keepe your berth to windward."
Berth came to be adopted more widely into the language, just meaning 'distance from'. There are several such figurative uses of the it in the 17th and 18th centuries - 'a good/clear/strong berth' etc. We have to wait until 1829 for Sir Walter Scott's Letters on demonology and witchcraft for 'a wide berth' though:
"Giving the apparent phantom what seamen call a wide berth."