In the sentence "They were from the Spanish bark San Lucar that had bad luck to go on rocks out there," the word "that" functions as a relative pronoun introducing a restrictive relative clause.
The clause is restrictive (defining)—it specifies *which* San Lucar (the one that wrecked). No commas. In formal American English, "that" is preferred for restrictive clauses; "which" for non-restrictive (with commas).
"That" = the ship which / the one that. It points back to the noun and adds essential identifying information.