1 Peter 3:18-20 gives us the context; it says,
For Christ also suffered once for sins, the righteous for the unrighteous, that he might bring us to God, being put to death in the flesh but made alive in the spirit, in which he went and proclaimed to the spirits in prison, because they formerly did not obey, when God’s patience waited in the days of Noah, while the ark was being prepared, in which a few, that is, eight persons, were brought safely through water.
(1) First view (Thomas Schreiner, John MacArthur, among others share this view): Many conservative scholars today believe these spirits in prison are fallen angels that Christ pronounced judgment on (after his death and resurrection). They say that Peter was influenced by 1 Enoch, a book of Jewish pseudapigraphal, or counterfeit, writings that claim to be written by whomever they are named for; but they were actually written some 200 years before Christ. 1 Enoch is about the Enoch in Genesis who was taken to heaven. 1 Enoch mentions fallen angels who marry and sleep with women in Noah’s day, producing children. That’s what they believe Genesis 6 is about (quoted here in 1 Peter); that evil angels corrupted the human race by marrying and breeding with them. And so God destroyed them in the flood and now preaches judgment on them.
(2) Second view (what I think; Wayne Grudem and Augustine share this view): The context of 1 Peter gives us a clue. In 1 Peter 1:10-11 we see that the Spirit of Christ indwelt Old Testament prophets; He spoke in them and through them. And so it appears that Christ is preaching through Noah to those who would not repent during the time it took Noah to build the ark. In fact, 2 Peter 2:5 calls Noah a herald, or preacher of righteousness. Noah must have had conversations with his contemporaries about why he was building the ark, warning them of the coming judgment. So, Christ spoke through Noah to living people on earth; not angels, but living, breathing, sinful man—those who did not repent, those who were judged, and those who now reside in prison in spirit form, waiting for that great day of final judgment. God had said that His Spirit would not dwell with man forever (Gen 6:3), yet mercy was extended through warning. That warning was refused. I think that best fits the context. People are going to revile you even when you do right, but just as Noah did, appeal to them with a good conscience telling them of the deliverance available, to flee from coming judgment.
Regardless of what view you take, Peter’s main point remains: God is righteous in his judgment, just as He was in the days of Noah.