Jem is comparing the people of Maycomb to a caterpillar in a cocoon because they are sheltered.
Jem has always felt safe in Maycomb, surrounded by good people. Nothing could ever go wrong, because he was protected and Maycomb was protected. During the trial, Jem sees that Maycomb is not immune to trouble. It actually has a darker side, scene in how people behave toward Tom and his family.
Like somethin' asleep wrapped up in a warm place. I always thought Maycomb folks were the best folks in the world, least that's what they seemed like. (ch 22)
Jem has never noticed the racism before. He was aware that Negroes were not treated as equals, but never really understood until he saw a jury convict an innocent man. Then he understood what Miss Maudie had said about his father being called upon to do the work others could not do. Atticus saw the town for what it was, and held a mirror up to it so it could see itself.