Genesis 39:20 says that Potiphar put Joseph into the prison where the king’s prisoners were confined. The NIV Study Bible makes this comment:
Potiphar put Joseph in the “house of the captain of the guard” (40:3) – certainly not the worst prison available.
There is no information to back that up. However, the ESV Study Bible makes this comment:
The law codes of the ancient Near East, including OT legislation, do not employ punishment by imprisonment in jail. Yet the practice is well known and attested in ancient Egyptian literature; therefore, this story fits well with the culture of ancient Egypt.
Genesis 40:2 says Pharaoh’s chief cup-bearer and chief baker ended up in the same prison as Joseph which was “in the palace of the captain of the guard”. Clearly, this is where prisoners of the King were detained at Pharaoh’s pleasure.
You ask if Joseph could have ended up in a different prison, one that was not under the control of Potiphar. After all, Joseph was not part of the household of Pharaoh, the King. Joseph was a Hebrew slave. He had angered Potiphar, not Pharaoh. Yet Potiphar saw fit to put Joseph in a prison that was reserved for prisoners of the King. It is not unreasonable to think that there were other places for “lesser mortals” – perhaps common criminals. But the Bible does not say.
What the Bible does show is that God had a plan for Joseph and that God was orchestrating events. Even Joseph recognised this after he had been released from prison and God had given him the interpretation of Pharaoh’s dreams:
Joseph said to them, “Don’t be afraid. Am I in the place of God? You intended to harm me, but God intended it for good to accomplish what is now being done, the saving of many lives” (Genesis 50:19-20).
It was no accident that Joseph ended up in the prison that housed Pharaoh’s enemies.