"God, His way is perfect" and so on (II Samuel 22:31 and Psalms 18:31), for all the ways of the Holy One, blessed be He, are perfect. For what does it matter to the Holy One, blessed be He, whether one ritually slaughters an animal and eats it, or stabs an animal to death and eats it? Does it benefit Him or harm Him? Or what does it matter to Him whether one eats unclean things or eats clean things? Rather, "If you are wise, you are wise for yourself; [and if you scoff, you alone shall bear it]" (Proverbs 9:12). Behold, the commandments were given only in order to refine the creatures by means of them, as it is said, "The word of the LORD is refined" (II Samuel, there). Why? Because He is a shield over you, [as it is said,] "He is a shield to all who take refuge in Him" (there). Thus, "These are the living creatures that you may eat" (Leviticus 11:2).
Why God Gave the Dietary Laws to Refine Israel
Midrash Tanchuma Buber, Shmini 12:2
האל תמים דרכו וגו' (ש"ב כב לא ותהלים יח לא), כי כל דרכיו של הקב"ה תמימות הן, וכי מה איכפת להקב"ה בין שוחט בהמה ואוכל אותה לנוחר בהמה ואוכל אותה, כלום מועילו או מזיקו, או מה איכפת לו בין אוכל טמאות לאוכל טהרות, אלא אם חכמת חכמת לך [ולצת לבדך תשא] (משלי ט יב), הא לא ניתנו המצות אלא לצרף בהן [את הבריות] שנאמר אמרת ה' צרופה (ש"ב שם), למה שהוא מגן עליך, [שנאמר] מגן הוא לכל החוסים בו (שם), הוי זאת החיה אשר תאכלו.