Our Gemara on Amud Beis states that a halachic male minor who is nine years and one day old can perform the mitzvah of Yibum. However, the status of this marriage is not complete until he consummates as a bar mitzvah, and if he dies before doing so, and now his wife falls to yibum to another brother, she must have chalitza and not yibum. There is some discussion amongst the Rishonim about whether the marriage is valid according to Torah law, and then invalidated by the rabbis, or if the marriage is not fully valid even from Torah law (see Ramban). In any case, the basic idea is that the yibum of a minor, though effective in some manner, is incomplete.
Be'er Mayim Chaim, Beresihis (38:11:3) uses this idea to explain that Yehuda was genuine in asking Tamar to wait until Shelah grew up before attempting Yibum, unlike Rashi. Rashi (Bereshis 38:11) says that Yehuda had no intention of marrying her off to Shelah, not after both of his other sons, Er and Onan died from marrying her. He was just pushing her off, because he was afraid that she was a Katalonis who somehow caused the deaths of her prior husbands. (See Psychology of the Daf, Yevamos 30.)
According to Be’er Mayim Chayim, Yehuda genuinely wanted to wait until Shelah was bar mitzvah, as then he would be able to perform the mitzvah of yibum fully and would be protected by virtue of being engaged in a mitzvah. As it states in Ecclesiastes (8:5), שׁוֹמֵ֣ר מִצְוָ֔ה לֹ֥א יֵדַ֖ע דָּבָ֣ר רָ֑ע. However, if he did Yibum as a minor, he would not be doing the mitzvah fully and may not be protected from whatever destructive forces (spiritual or physical) that surrounded Tamar.
Where did this trend start of projecting lomdishe halakhic thinking back into the time of the Avos?
(Another related style of derash, are the various Talmudic and halakhic awareness attributed to the motives of even evil protagonists. Haman makes a lomdishe argument, see Pri Tzaddik Shushan Purim 1:1, and of course Pharaoh too. In Shemos Rabbah 1:18 Pharaoh knew that Hashem punishes measure for measure, and since God made an oath to no longer bring a deluge, he thought he could drown the Jewish infants with impunity. Little did he know, Hashem’s oath applied to the whole world, not one nation. Thus, the Egyptians met their fate drowning in the Red Sea. For more Lomdus on the part of Biblical protagonists and villains, see Psychology of the Daf, Kesuvos 98. Less surprising but also interesting, the Gemara Bava Basra 119b explains how the daughters of Tzelophchad were darshaniyos.)
In any case, back to Avos, we have the Mishna Kiddushin 82a famously telling us that Avraham kept the entire Torah:
וַה' בֵּרַךְ אֶת אַבְרָהָם בַּכֹּל מָצִינוּ שֶׁעָשָׂה אַבְרָהָם אָבִינוּ אֶת כָּל הַתּוֹרָה כּוּלָּהּ עַד שֶׁלֹּא נִיתְּנָה שֶׁנֶּאֱמַר עֵקֶב אֲשֶׁר שָׁמַע אַבְרָהָם בְּקֹלִי וַיִּשְׁמֹר מִשְׁמַרְתִּי מִצְוֹתַי חֻקּוֹתַי וְתוֹרֹתָי
“And Abraham was old, well stricken in age; and the Lord had blessed Abraham in all things” (Genesis 24:1). We found that Abraham our forefather fulfilled the entire Torah before it was given, as it is stated: “Because that Abraham listened to My voice, and kept My charge, My commandments, My statutes, and My laws” (Genesis 26:5), which indicates that Abraham observed all the mitzvos of his own accord and was rewarded in his old age as a result.
It is not limited to Avraham, but also we find a midrash that Yaakov kept all 613 mitzvos (see Rashi Bereishis 32:5).
The Maharal (Tiferes Yisrael 20) draws a distinction between Avraham and Yaakov. Avaraham had so absorbed the depth of the Torah, that he implicitly felt as if he was commanded to follow everything. On the other hand, Yaakov did it out of a sense of what was proper but not as a fully obligated Jew. This leads to a whole discussion of how could Yaakov have married two sisters, a Torah prohibition. But if you are not feeling the Torah as a command from God, but rather an ethical requirement, other ethics can supersede this ethic, such building a family with a proper, devout woman.
The Ramban states that the Avos only kept the Torah in Eretz Yisrael and this was the place of its ultimate and complete fulfillment, see Ramban Bereishis 26:5. The Ramah in a Teshuva (10) simply says, unlike Avraham, Yaakov did not keep all the mitzvos, as evidenced by his marrying sisters.
The Maharal in Gur Aryeh (Bereishis 46:10) makes a fascinating distinction to explain how Yaakov could marry sisters. The Avos only kept the positive mitzvos and not the prohibitions. Now at first this would seem to be counter-intuitive, since a positive command is less severe than a negative prohibition. One must give up all one’s money to avoid violating a Torah prohibition, unlike a mitzvas aseh, which one must only spend up to a fifth of his funds. (See Shulkhan Arukh OC 656:1). The Gur Aryeh cleverly argues, if God doesn’t command you specifically, you can always do more mitzvos out of intuition or ruach hakodesh, because mitzvos are supposed to accomplish something. However, negative commandments do not accomplish anything. Instead, they are prohibitions against something that God deems destructive. If God did not issue a command yet, nu, so it is not such a bad thing to do. However, it always is a good idea to do more. So the Avos kept the Torah in a sense of the commandments, not the prohibitions.
One final peshat: Ben Yehoyada in Kiddushin (82a) says the Avos studies the mitzvos and that is how they fulfilled them, by understanding their depth and meaning. They did not necessarily perform them. Reading between the lines, I think he means that they understood the essence behind the mitzvos and therefore fulfilled them in their own way, without specific regulations. Just as an example, clearly tefillin and mezuzah are to remind us of the yoke of heaven on our hearts, heads and homes. One can accomplish the essence of this mitzvah through meditation alone. The Avos did this without concrete performance of mitzvos down to the regulations of shape and size of tefillin or letters and parchment of a mezuzah.
Returning to our original point about anachronistically projecting lomdus onto biblical figures in derash, we can use this same idea. It doesn’t have to mean that Yehuda opened up mesechta Yevamos (of course an Oz Vehadar edition – only the best for royalty!), or that Pharaoh studied Derech Hashem. They certainly could have intuited the basic spiritual ideas, and the midrash just used the language of lomdus to metaphorically express the concept. Pharaoh could have been aware of the idea that God punishes in a fair manner of retribution and thought to outsmart him, or lehavdil, Yehuda could have understood conceptually that shelah might not yet be at age to properly do the mitzvah of yibum and properly be protected.