The Anaf Yosef observes that there seems to be a contradiction in the medrish. Originally, Hashem specified a single mitzvah about what one could or could not eat, and later it says that the baby has to accept all the mitzvos in the womb;so were all mitzvos, or only one mitzvah, discussed in the womb? We must therefore say that we learn from this that all of the mitzvos and all Torah learning is dependent on the mitzvah of not eating something spiritually impure. The explanation behind this is based on what earlier rabbis have taught us, that the reason why Hashem distanced the Jews from these spiritually impure things is because they are so disgusting and impure that it covers a person’s heart with impurities and causes one to forget his Torah learning and the necessary means to obtain the Torah.He therefore distanced them and warned against them [eating non-kosher foods]. Now what the medrish says makes sense; Hashem explains to the baby before he leaves his mother’s womb that this he is allowed to eat and this he isn’t;then, if he accepts this mitzva,h he will accept the entire Torah and its mitzvos. For it is for this reason that Hashem warned us [about not eating non-kosher], in order to understand and have the necessary means to obtain the Torah.
We learn from here something absolutely incredible and awesome about the true understanding of Torah and proper service of Hashem! One can have the intellect of an Albert Einstein and a photographic memory, but if he eats non-kosher, which sullies his heart and spiritual essence, he won’t be able to fully grasp the Torah and observance of its mitzvos with crystal clarity. It is true that being smarter might make it easier to pick up and get into Torah learning, but the precision and absolute intensity needed to understand the minutia and profundity of the Torah, to the point of properly observing it, will not be there.
The Torah is the pristine and holy gift of Hashem to mankind; one must be cognizant of that at all time and must treat it with the utmost respect and sacredness. In this way one can truly understand and appreciate the Torah and observance of mitzvos, in order to fulfill G-D’s will.