They said to one another, “Surely we are being punished because of our brother. We saw how distressed he was when he pleaded with us for his life, but we would not listen; that’s why this distress has come on us.”Genesis 42:21
Because of the famine, Joseph's brothers go to Egypt and bow down before Joseph (who they don't recognise) in fulfilment of Joseph's dreams. They assume that this is all happening as punishment from God for their treatment of Joseph. They are half correct. This IS happening as a result of them selling Joseph into slavery (otherwise he wouldn't be here) but it is not punishment from God, but God turning their sin into a blessing. They will be saved because of this. They receive grace in exchange for sin.
God takes my sin and produces blessing. I receive grace in exchange for my sin. What I am experiencing now may be a consequence of my sin but that does not mean it is bad or a punishment. God only gives good gifts, and good consequences.