Here’s me attempting to explain to a friend a huge unknown/misunderstood narrative of the Bible as quickly as possible:
In the Old Testament there are beings known as “the sons of God.” This is a blanket phrase used for any kind of spiritual being. Genesis 6 tells us that some of these spiritual beings (angels, more or less) decided to violate the boundaries God set in place and procreate with human women, giving rise to a new race of sorts known as the Nephilim (AKA giants). The giants are likely a part of the reason for the flood as they have added another level of sin into the world.
But the flood doesn’t end them. They’re still around in the book of Numbers and need to be conquered in order for Israel to take the Holy Land. And at this point they’re not just called the Nephilim—they’ve sorted themselves into clans known by other names, like the Anakim or the Rephaim, and some of them are living among human clans as well—like how Goliath lived among the human clan of the Philistines. The giants were a huge focus of the holy war—in fact, it seems the only tribes Israel was supposed to go to war with were tribes where giants were present. All other tribes could be displaced. The book of Judges ends by saying that Israel got lazy and didn’t finish getting rid of the giants like they were supposed to. David then picks that task back up when he goes to war with Goliath and some other giants like Ishbi-benob, and so on. Through David they finally finish the job.
There was a very popular Jewish book around Jesus’ time called “Enoch.” This book was written from the perspective of what it might have been like for the holy man in Genesis, named Enoch, to live among the giants. While this is not a Bible book, it was a well-known book that informed the Bible writers. In fact, the Bible directly mentions the writings of this book in passages like Jude 14. And if we were to read the book of Enoch, we would hear more clearly what Jude is trying to say in verses like Jude 6.
In the book of Enoch, the angels that decided to procreate with women and create giants were sentenced to the underworld in a spiritual prison of sorts, where they’re locked up in chains until the end comes and God judges them. Their sentence is already final and they are stuck there until the “Day of the Lord.” Jude and 2 Peter 2:4-5 agrees with Enoch on this. 1 Peter 3:18-20 also says that when Jesus was dead for three days, he visited these angels (spirits) in prison. The idea there is that just as Jesus was to Paul a “second Adam,” he was also to Peter a “second Enoch.” In the book of Enoch, Enoch goes to these angels in prison and tells them they will be judged for what they’ve done. Peter sees Jesus doing the same thing—going up to these angels while they’re still in prison and telling them that they will be judged for what they’ve done. They think they’ve just beaten Jesus by killing him on the cross, but they couldn’t be more wrong. Their judgment is still on.
And on a final note, the Bible says that after the Rephaim (giants) died, they went on to be spirits in the underworld. The Jews of Jesus’ time believed that demons weren’t only fallen angels and false gods, but also the disembodied souls of the giants. This is especially written down in books like Enoch and other popular Jewish books. These giants weren’t made by God and they don’t belong in Heaven, so they’re out afflicting people in spiritual form as demons. That’s likely part of the reason they’re sometimes called “unclean spirits” in the Bible. They exist because of the unclean circumstances of angels and humans breaking boundaries.