This is off the top of my head, so I could be barking mad, but this is how I remember it. Spoilers for Kizumonogatari, Nekomonogatari Black, and Nisemonogatari ahead.
Shinobu, in Kizu, tells Koyomi that head-patting is some kind of intimate act of subservience between a vampire servant and master. Koyomi thinks this is a little weird, but goes along with it.
At the end of Kizu, Tsubasa deduces that Shinobu wanted to die the whole time. Koyomi refuses to grant her this, and instead brings about the situation where he's an asymptotically human pseudo vampire and Shinobu is a mostly powerless asymptotically vampiric pseudo human who has to suck Koyomi's blood to survive. Shinobu is furious, and doesn't talk to Koyomi until Karen Bee.
In Neko Black, Shinobu helps defeat Black Hanekawa. Afterwards, Koyomi goes to pat her on the head as a reward, but finds that she's wearing that strange pilot hat. She got the hat to show Koyomi that she was still pissed at him and wasn't going to let him pat her on the head.
Later, in Tsubasa Cat, Shinobu stops being angry at Koyomi and starts living in his shadow. In Karen Bee, she even comes out to talk to him when he's in the bath. Since she's not mad at him anymore, she stops wearing the hat, since she doesn't need to stop him from patting her head.
Edit: Now with actual evidence.
Kizumonogatari, Chapter 4 establishes that head-rubbing is regarded by Shinobu as a sign of obedience. Koyomi has just allowed Shinobu to turn him into a vampire, and Shinobu has asked him if he understands that he must be subservient to her. The first to speak is Koyomi.
“Huh, an ambiguous answer——do you really understand?”
“Um, umm——I understand.”
“Then as a sign of obedience to me, rub my head!”
She said majestically.
Uwa, her hair is really soft.
Although there is a lot of hair, it‘s really smooth.
“....That‘s the sign of obedience?”
“You don't know that?”
She looked at me with contempt.
Vampires use a different set of rules.
Here's Nekomonogatari Black, Chapter 13, where Koyomi goes in to thank Shinobu for her help and finds her wearing the hat. Oshino also tells Koyomi that he gave her the hat. I massaged out some of the grammar mistakes in the translation.
I even wanted to stroke her head.
The sign of obedience—though I wouldn't call it that.
Still, I thought she could let me do at least that—I thought she
would certainly let me thank her.
My expectation was largely unfulfilled.
The sense of omnipotence of the look from above in epilogues didn't
As I arrived and met her in the classroom on the first floor, the
little vampire girl was wearing, of all things, an enigmatic helmet
with goggles, of the type you wear when riding a moped.
I couldn't stroke her head like this.
“Ah, that? Vampire-chan badgered me about it. After all she is
the one who solved the whole cat thing, so I gave it to her as a
The quotes don't explicitly say that Shinobu was wearing the hat to stop Koyomi from rubbing her head, but it seems pretty plain from the context. It was her way of telling Koyomi, without deigning to speak to him, that she hadn't forgiven him.