Indeed, in Devarim 21:16 - 17 it states that the father cannot favor the son of the beloved wife over the older son of a hated wife. But that is with all else being equal, with the only reason one favors the younger firstborn being love for the more beloved wife.
Reuven lost his firstborn rights for sleeping with Bilhah, his father's concubine. This is stated explicitly in Divrei Hayamim I, 5:1-2:
א וּבְנֵי רְאוּבֵן בְּכוֹר-יִשְׂרָאֵל, כִּי הוּא הַבְּכוֹר--וּבְחַלְּלוֹ יְצוּעֵי אָבִיו, נִתְּנָה בְּכֹרָתוֹ לִבְנֵי יוֹסֵף בֶּן-יִשְׂרָאֵל; וְלֹא לְהִתְיַחֵשׂ, לַבְּכֹרָה.
ב כִּי יְהוּדָה גָּבַר בְּאֶחָיו, וּלְנָגִיד מִמֶּנּוּ; וְהַבְּכֹרָה, לְיוֹסֵף.
1 And the sons of Reuben the first-born of Israel--for he was the first-born; but, forasmuch as he defiled his father's couch, his birthright was given unto the sons of Joseph the son of Israel, yet not so that he was to be reckoned in the genealogy as first-born.
2 For Judah prevailed above his brethren, and of him came he that is the prince; but the birthright was Joseph's.
As I note in this post, this idea roughly corresponds to the legal codes in the time of Yaakov. We see in the Code of Hammurabi:
- If a free man has sexual relations with his father's first wife, who is the mother of sons, after the death of his father, that man shall lose his paternal inheritance.
- If any one be surprised after his father with his chief wife, who has borne children, he shall be driven out of his father's house.
In this case, it was a concubine during his father's lifetime, and he did not lose the entirety of the inheritance, but just the firstborn rights. Still, it is of a similar nature.
So, even if we want to say that this Torah law applies to Yaakov prior to the giving of the Torah, there is a cultural and legal context in which to apply the law, just as is stated in Divrei Hayamim (and quite possibly in the ambiguous and cryptic parallel text in parshat Vaychi).