To understand the meaning of “the living and the dead” in verse 5 you need to look at verse 6.
6 For this cause was the gospel preached also to them that are dead, that they might be judged according to men in the flesh, but live according to God in the spirit.
Here is the key to understanding the context. Obviously, the gospel was not preached to those who were physically dead. On the contrary, the gospel was preached to those who were spiritually dead or in other words, who had not crossed over from death to life.
As Romans 8:6 puts it:
6For to be carnally minded is death; but to be spiritually minded is life and peace.
The bible defines those who are carnally minded to be those who live after the dictates of their own heart and will. If you were a Jew, you lived after the Law of Moses and according to Romans 10:3, the Jews went about to set up their own righteousness through attempting to keep the law. The Gentiles, did not have the law, however according to Romans 4, they showed the evidence of the law written on their hearts since they were acting just like the self righteous Jews. The Gentiles were either by “accusing” others (if they didn’t act exactly as the Gentiles thought they should) or by “excusing” those who acted just as they did. In other words, they were showing partiality and that is evidence of living after the law. The bible says to live this way, ie on your own without the faith of Jesus Christ, is to be carnally minded and spiritually dead.
However, if you live by faith and believe that Christ died to atone for your sin, then that faith imputes to you God’s righteousness and by Romans 8:6 you are now spiritually minded. The result of being spiritually minded is life and peace with God.
1 Peter 4:6 then states that the Gospel was preached to those who were living carnally (after the dictates of their own will) so that they could be judged “according to men in the flesh”. To live after the flesh is to live according to the Law of Moses, ie try to attain righteousness (perfection) yourself, by living a moral life. As Romans 7:5 put it”
5For when we were in the flesh, the motions of sins, which were by the law, did work in our members to bring forth fruit unto death.
Again, according to Romans 4, the Jews were judged by the Law of Moses in order to demonstrate that they could in no way come close to live perfectly by the law. Remember, Deuteronomy 28 tells us that we must do “everything” written in the law in order to receive the blessing of God. That’s how the New Testament tells us that “there is none righteous, no not one”, (Romans 3:10) and as James 2:10 says that if you offend in one point of the law you are guilty of all.
The Gentiles then were also judged by the Law of Moses but not directly. Again, according to Romans 4, the Gentiles “demonstrated” that they had the law written on their heart, the evidence of which was their behavior (ie, either “accusing” or “excusing”). So, whether Jew or Gentile, all are judged after the flesh (the law).
So, as 1 Peter 4:6 rightly states, that the Gospel was preached to everyone in the flesh (since all sin and needs to be saved) so that they might live by faith through the Spirit of God.