The Perashas Derachim asks from our Gemora (Nedarim 28a) which states that the law of the kingdom is the law and we do not allow a person to vow deceptively. If so, this should certainly apply by The Holy One blessed is He, Who is the King of all Kings. How could Klal Yisroel use the coercion as an excuse? The law of the kingdom is the law, and they took an oath obligating themselves to perform His mitzvos!
He answers that Rabbeinu Tam holds that the principle of the law of the kingdom is the law is only applicable if the king decrees on all his subjects. However, if the decree is issued only on part of his kingdom, this principle does not apply. Since Hashem is the King over all the nations of the world and He only forced Bnei Yisroel to accept His mitzvos, this principle would not apply and hence, a claim of coercion can be effective.
It emerges that regarding the seven mitzvos that were given to all Bnei Noach, the principle of the law of the kingdom is the law would apply, and a claim of coercion would not be valid.
According to this, we can explain the argument between Pharaoh and the midwives. Pharaoh asked them, “Why didn’t you listen to my commandment? The law of the kingdom is the law and since I the king decreed that all the Jewish children should be killed, you are obligated to listen to me!” They responded to him, “Your decree is not a universal one; it was only issued regarding the Jewish children and not to any others. Accordingly, the principle does not apply and we are not obligated to adhere to the laws of the kingdom. Thereupon, Pharaoh immediately decreed that all children born must be thrown into the sea.