Different commentaries (such as the Ibn Ezra and the Ramban) on the verse in D'varim address the issue in different ways, but I'll produce a rough translation of the Y'rushalmi (Sotah 1:10), which discusses the two passages (please pardon any mistakes in this hasty translation):
It is written (Shmuel II, 1:18): "And David eulogized this elegy… and he said 'To teach the Children of Yehuda the bow, behold it is written in the Sefer HaYashar'." It does not make sense to lament about the Children of Yehuda needing to learn the bow then.... Rather, David said: When the righteous die [in this case Shaul and Yonasan], the enemies of Israel come and harass Israel. [David indeed had to prepare his bow and practice with it, and he was lamenting the deaths of Shaul and Yonasan that led to this].
"Behold it is written in the Sefer HaYashar (the Virtuous Book, i.e. the Torah)." There are two opinions on what this is. One says it is the Book of B'reishis [which details the lives of our virtuous forefathers -Rashi], and the other says it is the Chomesh Pikudim (i.e. the Book of B'midbar).
QUESTION: The opinion that it refers to B'reishis makes sense [since Yehuda is described there as having his hand on the neck of his enemies, which is a mandate for David to prepare for war -Korban HaEdah commentary]. But what war is found in the Book of B'midbar [that serves as a precedent for David needing to prepare for war under those circumstances]?
ANSWER: "And the Children of Israel travelled from Be'eros B'nei Ya'akan to Moserah. There Aharon died" (D'varim 10). But did Aharon really die in Moseros? He actually died at Hor HaHar, as is written, "And they ascended to Hor HaHar… and Aharon died there" (B'midbar 20). Rather, when Aharon died, the clouds of Glory [that had henceforth protected Israel in Aharon's merit] departed, and the Canaanites sought to attack Israel, as is written [immediately after Aharon's death], "And the Canaanite King of Arad dwelling in the Negev heard that Israel came by way of Asarim [and he waged war against Israel]" (ibid. 21).
What is "by way of Asarim"? [The King of Arad] heard that Aharon, who was their great guide for them on the way, died (Asarim could be read to mean "guidings". "Let us come and attack them," [the King of Arad said]. And Israel sought to return to Egypt, and they travelled backwards through eight locations [including their present location and their destination location], and the tribe of Levi pursued them and killed eight families of them, and they killed four families of Levi, as is written (Chronicles I 26), "Of the Amramites, of Yitzhar, of the Chevronites, of the Uzielites." When did they return? In the days of David, as is written (Psalms 72) "The righteous shall flower in his days." They said, "What caused us all this bloodshed?" They answered, "Because we did not perform chesed for that tzadik [Aharon]." And they went and eulogized him and they performed chesed for that tzadik. And the verse treated it for them as if he died there and was buried there, where they did chesed for that tzadik.