Minor spoilers ahead for It Chapter Two. The city of Derry hides a terrible darkness at its heart: an evil that sows fear and disbelief and lets residents turn a blind eye to horrors both mundane and beyond the pale. Also there's a multidimensional shapeshifting entity living in its sewers that usually appears as a clown called Pennywise (Bill Skarsgård). Neither the movie nor Stephen King's 1986 novel shy away from portraying the child-killing entity as just one of Derry's problems, an active amplifier of the rottenness already present among its residents, which is why the Stephen King It Chapter Two cameo is both apropos and true-to-life.
In the sequel, Bill (James McAvoy), now a successful horror writer (and a clear King stand-in) returns to Derry to fulfill his Losers' oath. Walking downtown, he sees his old bike in an antique store window and has to buy it. Stephen King himself is the store proprietor, deadpanning his way through the conversation with the stone face and bone-dry humor of a true Mainer. Which is exactly what King is — he's lived all over the state his entire life. But his appearance in Derry means more than just a happy surprise for fans and a bright moment in a dark film.
In a 1979 essay for The Bangor Daily, King plainly states that "the novel about the small city named Derry" (what would eventually become It) was based on Bangor, where he and his family chose to move. "When people ask Why do you live in Bangor? they are also revealing something about themselves...This particular interrogatory says of the questioner I would expect you to be living in some rather more luxurious place...And I think it also says something rather more damning: You need to justify your decision to live here, because it seems to me a bit insane, at least on the face of it — if I could afford to do so, I could be out of here tomorrow." Certainly all the Losers save Mike (Isaiah Mustafa) fled as soon as they could and promptly forgot everything about Derry. But King not only stayed in Bangor, he came back.
According to The Stephen King Companion, he and his wife Tabby lived in Bangor before the success of Carrie but bought their first house elsewhere in Maine. When it came time to move again Tabby wanted to go to Portland, and the author wanted to return to Bangor, which King thought of as "a hard-ass working class town... and I thought that the story, the big story, I wanted to write, was here. I had something fixed in my mind about bringing together all my thoughts on monsters and the children’s tale Three Billy Goats Gruff, and I didn't want it to be in Portland because Portland is a kind of yuppie town."
King wasn't blinded by blue-collar myth; he was also well aware of the bigotry present in the area. "There had been a story in the paper about the time we decided to move up here about a young man who came to the Jaguar Tavern during the Bangor Fair. He was gay and some guys got to joking with him. Then the joking got out of hand, and they threw him over the bridge and killed him," he said, per The Stephen King Companion. "And I thought, that's what I want to write about." You might recognize that scene from It the novel or the opening scene of Chapter Two; Pennywise shows up after the attack, an echo of the cruelty already present. Just like the Losers had to face memories they'd rather block, King wanted to face the reality of where he came from and lived.
His Chapter Two cameo as a townie old-timer brings the real King and his fictional counterpart together — two people deciding they're not going to run but to stay and root out the problems right where they are. Not everyone has the ability to do that, and as the horrific attack that inspired It shows, those that try to fight often face terrible consequences. King's cameo is just reinforcement that he's not going anywhere anytime soon.