There is a book about small spiders that pop into people's skulls and control them using the pain center of the brain. Does anybody know the title of this book?
Possibly In Other Worlds by A. A. Attanasio.
There is an alien race called the Zotl that control humans by attaching to the back of their head and burrowing into the pain centre:
Almost instantly, the spider dashed over his shoulder and onto his back. .With flailing arms, Gareth tried to brush it off while he rushed to the door. Its legs scratched the back of his neck and tangled in his hair, and as he reached for it, the thorns spurring the creature's long front legs stabbed his wrists. He slammed into the doorjamb, and spun about to see the black shivering bale in the corner lean over and reveal a glistening blue slugface, frothing with a putrescent ferment of juices. The sight of it made him scream.
The spider gripping the back of his head shimmied tight against his nape, and its powerful beak jabbed him, piercing his skull with a sound like the crunch of gravel. Its probe needled into his brain, and jagged electric colors tore through Gareth with a searing agony. His body thrashed, and his brain went rubbery. He couldn't move. He couldn't yell.
But then he was moving. Through the jackhammer throb of his hurt, through the sheets of flame snapping within him, he saw himself weightlessly rising to his feet and sleepwalking toward the slugfaced thing in the corner.
The Zotl also eat brains:
A zotl feast is ghastly. The male zotl piths the back of the skull, and a needlefine tubule is inserted into the amygdala, the pain center of the brain. The human is paralyzed but quite aware of what is happening. The awareness is important to the zotl's digestion, so the captive brain is injected with a serum that heightens perceptions. Then the pain center is activated, and the human suffers. The torment is horrendous, a molten tearing, all the more terrible because the body is left intact and is nourished by the zotl's glucose wastes. The feeding can last for weeks."
That's a very vague description, but it might be This Book is Full of Spiders by David Wong (sequel to John Dies at the End). It's been a while since I read it and I don't remember much of the plot other than the brain spiders; a few other details I recall are a plague that was widely misinterpreted as a zombie outbreak, a scene with a drone pilot who disobeyed orders in order to save civilians, and one of the main characters was a woman with one arm - does any of that ring a bell?
A year has passed since the events of the previous novel. John and David still live in UNDISCLOSED. David continues to work in the video store, and John works at whatever jobs he can temporarily hold down.
In the opening pages of the book David and John witness what appears to be a large military convoy driving through the outskirts of town. The convoy crashes, and the pair go to investigate. They discover a strange box guarded by G.I.Joe like action figures in the back of one of the convoy’s trucks.
One night while asleep in his bed, David is attacked by a spider-like creature. When a police officer arrives to investigate the disturbance, he is unable to see the creature, which then turns on him. The creature takes control of the officer’s body, inducing a zombie-type infection. Despite the efforts of David, John, and a detective named Lance Falconer, the infection spreads throughout the town, panic ensues, and the town is cordoned off in an attempt to stop the spread of the infection.
David and John become separated. David is captured and, assuming he may be infected, authorities imprison him in the hospital along with several hundred other presumed-infected. The hospital grounds are fenced off as a quarantine zone. Meanwhile, John makes his way to a town two hours away, where David’s girlfriend, Amy, goes to school.
John and Amy eventually make their separate ways back to UNDISCLOSED, each with the intention of finding and rescuing David. Meanwhile, David and several other hospital prisoners discover a tunnel in the basement of the hospital that will potentially lead them to freedom. David is prevented from escaping, which turns out to be fortuitous, as all of the escapees are slaughtered at the other end of the tunnel by would-be rescuers who believed the escapees to be zombies.
Could it be "Alien Prey" by John Peel?
One of the plot points in the book involves the realization that a town is infested with mind-controlling (alien) spiders - only a few kids ended up being immune. The spiders were well established enough that most people were infected as infants, but it was possible (and shown) for older people to be infected as well.
the kids were immune because they got infected by another race, one at war with the spiders, via little crystals in their hands. Much less invasive than spiders in their brains, especially since said crystals didn't seem to have taken them over.
Said spiders did control by crawling into people's heads (and presumably mucking with their brains, though specifics are not included). There is a scene where a spider is seen exiting a person's skull after they are killed, and the cover itself has a spider-and-skull picture.
The book doesn't mention the pain centers or any such specifics, which doesn't quite match your description, and it also takes a while for the spiders to come out as the cause of various mysteries the kids were investigating - as something of a surprise for the protagonists. Even so, it seems like a decent match to your question.