Abraham had feared for his life when he went to Egypt (Genesis 12.11–13), but he quickly learned that he had no reason to fear harm from the Egyptians. However, later his grandson and his family would go down into Egypt, and things would start out well, but in time, the Egyptians would not treat Israel very good. Moses recorded what the Lord said to Abraham about this situation,
Now when the sun was going down, a deep sleep fell upon Abram; and behold, horror and great darkness fell upon him. Then [the Lord] said to Abram: “Know certainly that your descendants will be strangers in a land that is not theirs, and will serve them, and they will afflict them four hundred years. And also the nation whom they serve I will judge; afterward they shall come out with great possessions. Now as for you, you shall go to your fathers in peace; you shall be buried at a good old age. But in the fourth generation they shall return here, for the iniquity of the Amorites is not yet complete” (Genesis 15.12–16).
The reason Israel would be in Egypt for four centuries would be that they needed a place to stay until the iniquity of the Amorites (the people living in the Land of Canaan), was complete. However, the Egyptians would take advantage of the peaceful Israelites and enslave them during that time. At the right time, the Lord said He would bring Israel out and judge Egypt.
We may not always see what the Lord sees, but we need to trust Him that He knows what He is doing.