Let us return to the beginning of the section. What did the Holy One, blessed be He, see fit to trace the lineage of Phinehas after this deed? For at the hour when Zimri son of Salu was stabbed together with Cozbi daughter of Zur, the tribes rose up against him and said: "Have you seen this son of Puti, whose mother's father fattened calves for star-worship? He has slain a prince of a tribe in Israel!" Therefore the verse came and traced his lineage: "Phinehas son of Eleazar son of Aaron the priest."
Why Scripture Traces Phinehas Back to Aaron the Priest
Midrash Tanchuma Buber, Pinchas 3:1
נחזור על תחלת הסדר. מה ראה הקב"ה לייחס פינחס אחר מעשה זה, שבשעה שנדקר זמרי בן סלוא עם כזבי בת צור, עמדו השבטים עליו, ואמרו ראיתם בן פוטי זה, שפיטם אבי אמו עגלים לעבודת כוכבים, הרג נשיא שבט מישראל, לכך בא הכתוב ויחסו פינחס בן אלעזר בן אהרן הכהן.