Peace be upon you. Scholars of Shia Islam have chosen to interpret the verse: "Today, those who disbelieve have despaired of [defeating] your religion; so fear them not, but fear Me. Today I have perfected for you your religion and completed My favor upon you and have chosen for you Islam as religion" as having been revealed on the day of Ghadir Khumm, explaining the matter of leadership after the Prophet Muhammad (peace be upon him and his family). It is clear that the context of this noble verse indicates that it is an interjection inserted within the larger blessed verse that was revealed to clarify the prohibitions of food and the necessity of it at times. If we were to remove these two sentences, the discussion about prohibitions would be complete. The Quran often includes important matters within verses that serve multiple purposes, which is a commendable rhetorical style among eloquent speakers. This is evident in the verse of purification.
One of the wisdoms that can be mentioned here is the emphasis on the importance of leadership in Islam, indicating that mere adherence to secondary legal rulings, such as the prohibition of certain foods, is insufficient. Rather, religion encompasses a set of valuable laws, guidance, and instructions that prepare a person practically and doctrinally to achieve the perfection befitting them in both worlds. The completion of religion and the despair of disbelievers from its demise occurs only when there is someone to preserve, defend, and guide the people, as the Prophet (peace be upon him and his family) did during his noble life, defending Islam against trials and doubts that disbelievers sought to use to erase the religion. Therefore, it is essential to have someone to complete the path, safeguard the Sharia from these trials and deviations, and continue the path of guidance. Thus, leadership is what completes religion and ensures its continuity after the Prophet's passing.
Some have suggested that the wisdom behind inserting these two sentences in the noble verse is to protect it from distortion and omission, as historical events have shown that some attempted to distance people from the idea of divine leadership. May you be successful in all good.