You have given too little context to determine whether the sentence is proper or not.
Suppose the context was Ahab was captain of a whaling ship, the Pequod, the crew of which the narrator, Ishmael, joined. Arab had lost a leg when the ship was attacked by a whale during a previous voyage. Here, "had lost" refers to a time before the past time when Ishmael joined the crew. "Was attacked" refers to the time when Ahab lost his leg. That set of tenses would not be an error in grammar.
The example might perhaps be considered a clumsy construction because of the use of the simple past to refer to the time when Ishmael joined the crew and to the earlier time when the whale attacked the ship. It would be less clumsy and clearer to write Ahab was captain of a whaling ship, the Pequod, the crew of which Ishmael joined. Ahab had lost a leg during an attack on the ship by a whale during a previous voyage. But clumsy is not the same as ungrammatical.