The root of the question begins with the pasuk itself: Hashem commands the earth to bring forth "eitz pri" — a fruit tree — but the earth brings forth only "eitz oseh pri," a tree that makes fruit, a gap the text itself seems to register (Bereishit 1:11-12).
Bereshit Rabbah 5:9 identifies this gap as the earth's transgression of the command, explaining that just as the fruit is edible, the tree itself was meant to be edible, and because the earth did not comply it was later cursed; one opinion there even says the earth overreached in the other direction, producing fruit even from barren trees out of a wish to fulfill its Creator's will, showing the midrash does not see this as simple disobedience but as a complex response to the command.
Chullin 60a:10-12 extends this motif of creation itself reasoning and reacting to Hashem's words, describing the grasses as drawing a kal vachomer about whether they must emerge grouped by species, which shows that Chazal depict the elements of creation as capable of a kind of responsive deliberation to the divine command, not mere mechanical growth.
Later meforshim grapple directly with how an inanimate earth can be said to sin. the Gur Aryeh (Bereishit 1:11) states plainly that the earth has no yetzer hara and cannot willfully transgress; rather, the earth, as part of the lower world, is intrinsically deficient compared to the heavens, so its product was necessarily incomplete, and this deficiency is described in the language of sin only metaphorically. Kli Yakar (Bereishit 1:11) cites the same teaching of Chazal that the earth sinned by not making the tree's taste like the fruit's, and uses it to explain why the ground was cursed only later, at the time of Adam's sin, tying the earth's deficiency to the larger curse of the ground.
Alshich offers that the earth, at that early stage of creation, still possessed a kind of spiritual vitality before it was coarsened by Adam's sin, giving it a form of bechirah and the capacity to act on its own judgment — it believed the Creator would not object to filling the land even with non-fruit-bearing trees, which is why it is described as having chosen and erred rather than merely failed mechanically.
Michtav MeEliyahu (Rav Dessler) reads the deeper meaning of this gap: a vessel whose taste matches its purpose entirely, with no flavor of its own, represents total devotion to its end, whereas a tree that keeps its own distinct woody taste reflects an admixture of other purposes alongside the primary one — and this same root, the mixture of competing purposes within one vessel, is identified as the source of the possibility of sin, of avodah zarah, and of the mingling of good and evil found in the Etz HaDaat itself.
Shenei Luchot HaBerit (Torah Ohr 14) likewise connects the earth's failure to produce wood that tasted like fruit to a deliberate holding back, comparing it to the hiding of the first light, suggesting the earth anticipated that future wicked people would misuse a world of total perfection and so withheld it, tying the tree's creation to the eschatological promise that even barren trees will bear fruit in the future.
The Rishonim press further on the mechanics of the pasuk. the Ramban (Bereishit 1:11) notes that the phrasing may include all trees under the general category of "desheh," and wonders why barren trees are not explicitly mentioned, suggesting that it was the later curse of the ground, "arurah ha'adamah," that turned some trees barren, rather than their having been created that way; and he cites the same Chazal that originally even barren trees produced fruit. Or HaChaim (Bereishit 1:11) and Or HaChaim (Bereishit 1:12) raise related textual difficulties, asking why the command's order delayed the grasses' emergence and why the creation account nowhere mentions a deliberate creation of barren trees, concluding that it was only after the curse of the earth that its strength diminished and many trees stopped bearing fruit, producing thorns and thistles instead.
The Sforno (Bereishit 1:11) adds a technical point about the phrase "eitz pri oseh pri le-mino," explaining that it excludes a hybrid of two species, which does not reproduce, showing that the pasuk's language of "after its kind" is bound up with the biological capacity to reproduce true to type.
Sifrei Devarim 72:1 offers a broader principle for understanding failures described in the text of being "unable" to do something: Rabbi Yehoshua ben Korcha distinguishes between actual capability and permission, as with the Israelites who could have driven out the Yevusi but were not permitted to, a distinction that bears on how one reads language of inability or non-compliance in the Torah without assuming the agent lacked the physical capacity.
Mishneh Halachos (13:216) contrasts the tree's original, unmediated creation with the later cursed state of the earth requiring human cultivation, and argues that human labor upon the soil nonetheless accords with the Creator's will, offering a further way of understanding the relationship between the earth's original creation and its subsequent, less perfect state.