The Rambam (Hil Tshuvah, end of ch 6) asks why the Egyptians deserved punishment for their enslavement of the Jewish people when Hashem had already decreed and told Avraham that the Jewish people were to be oppressed and enslaved in exile. Rather than receive punishment, the Egyptians can claim reward for fulfilling G-d's wishes! The Rambam answers that while the Jewish people were fated to be slaves of the Egyptian nation, each individual Egyptian had the moral choice to make whether to enslave or oppress his/her Jewish neighbor. The Rambam offers an analogy: G-d declares that there will be good people and wicked people, yet surely a wicked person cannot exempt himself from punishment by claiming that G-d has fated his wickedness! There will always be good and evil, but each individual retains the moral choice as to how to act.
Both the Ra'avad and the Rambam (Braishis ch 15) disagree with the Rambam's approach, but I want to focus here on the Lechem Mishne's claim that the Rambam himself already answered in a previous halacha the question he now raises. The L.M. is referring to the Rambam's discussion (Hil Tshuvah end of ch 5 ) of how humans can have free choice when G-d is omniscient and already knows all the choices we are destined to make. If G-d has foreseen that we will choose to sin, then if we act otherwise, doesn't that indicate a lacking in G-d's omniscience? But if we are predestined to a certain fate, why do we have moral culpability for our actions when free choice does not exist? The Rambam answers that the relationship between G-d and his knowledge is incomprehensible from our human perspective -- "lo machshivosai machshivoseichem" -- the coexistence of free choice with G-d's foreknowledge is a mystery. The Lechem Mishne writes that squaring G-d's revelation of the future enslavement of the Jewish people with the Egyptians having free choice and being punished for that enslavement falls under this same rubric of Divine mystery.
The Ohr Sameiach is blunt in his reaction to this Lechem Mishne: "kol hadibur ta'us" -- "the entire comment is mistaken." While it is true that G-d's internal knowledge does not hinder our free will, prophecy is categorically different and does lead to an inescapably predetermined outcome. Since G-d revealed to Avraham that his children would be enslaved, the Egyptians were fated to be oppressors. Therefore, Rambam needed to call on the distinction between individual choice and global destiny to resolve the issue of Egyptian punishment.
Yeshayahu haNavi tells us that G-d words, "lo yashuv elay reikam ki im asah eis asher chafatzti" -- G-d's words do not return empty; they accomplish their task. The Bnei Yisaschar in a number of places cites the Alshich's interpretation of this pasuk as teaching that while G-d's knowledge allows for free choice by man, once uttered, once converted to the spoken word, that knowledge predetermines an outcome. Hashem tells his father-in-law Yisro to remain with the Jewish people and not return home "ki dibeir Hashem tov al Yisrael" -- the goodness promised to the Jewish people cannot be undone by their mistakes or their wrong choices because that goodness was spoken by G-d and G-d's speech creates an irrevocable fate.