The word “berth” came into the language early in the seventeenth century from sources unknown.
It was a nautical term employed to mean roomway for a ship in which to operate.
The early phrase was “to give a good (or, a clear) berth to,” which meant, literally, to avoid, or to keep well away from, and we give it the same meaning today, though rarely with reference to a ship.