The explanation I have heard is that it is a sailing reference: a ship having three masts, each mast having three yards from which a square sail is hung thus, the whole nine yards is a ship under full sail.