In various places in Talmud Bavli, there are stories told that take place during the times of Torah or Neviim where people in the story quote verses from prophetic books that did not yet exist at the time the story took place. How am I to understand these stories? Are they not literal? Are the quoted pesukim something that was originally Torah sh'bal peh?
For example: The Gemara in Bava Basra 22a-b says over a story wherein Yoav only kills male Edomites in a war based on a misreading of the verse תמחה את זכר עמלק to mean to kill only the males ("zachor" instead of "zecher"). Yoav confronts his childhood teacher and the following exchange occurs:
שקל ספסירא למיקטליה אמר ליה אמאי א"ל דכתיב (ירמיהו מח, י) ארור עושה מלאכת ה' רמיה א"ל שבקיה לההוא גברא דליקום בארור א"ל כתיב (ירמיהו מח, י) וארור מונע חרבו מדם איכא דאמרי קטליה ואיכא דאמרי לא קטליה
Joab took a sword to kill him. The teacher said to him: Why do you want to kill me? Joab said to him: As it is written: “Cursed is he who does the work of the Lord with a slack hand” (Jeremiah 48:10), and you taught me incorrectly. The teacher said to him: Leave that man to remain as cursed. This is a sufficient punishment; there is no need to kill me. Joab said to him: It is also written: “And cursed is he who keeps back his sword from blood” (Jeremiah 48:10). There are those who say that Joab killed him, and there are those who say that he did not kill him.
Yoav lived hundreds of years before Yirmiyahu (Jeremiah) HaNavi. How are Yoav and his teacher bringing proofs from a text that would not be written for hundreds of years? How are we to understand this type of aggadata gemara?