The mention of the "cap" suggests the Tripods novels by John Christopher: The White Mountains, The City of Gold and Lead, and The Pool of Fire. However, the main character, Will, does not have a defective cap; he (and some other teens) run away to avoid being capped. They do, however, eventually fight to free the Earth from the dominion of the alien "masters" who have conquered the planet and rule it via their giant walking tripod machines.
Perhaps you read one of the later books, in which Will and other rebels wear nonfunctional caps (taken from the bodies of dead men) but not the first (in which the boys' flight from the tripods is detailed).
(Partial) book summaries, per Wikipedia:
The White Mountains (1967)
Life goes on largely as it had in the pre-industrial era, excepting that all adult humans are subject to Tripod control. Protagonist Will, a thirteen-year-old boy living in the (fictional) English village of Wherton, is looking forward to the next "Capping Day," until a chance meeting with a mysterious uncapped man named Ozymandias prompts him to discover a world beyond the Tripods' control. He is accompanied by his cousin Henry and a French teenager named Jean-Paul, nicknamed "Beanpole."
The City of Gold and Lead (1968)
After a year in the White Mountains, the resistance charges Will, Beanpole, and a German boy, Fritz, to infiltrate a Tripod city by competing in a regional sporting exhibition. Will, a boxer, and Fritz, a runner, win their respective contests, while Beanpole fails to win in the jumping events.
The winners are taken to the Tripod city in a pressurised dome astride a river. Inside the city, the boys discover the Tripods' operators, whom they refer to as the "Masters". Human males are slaves inside the cities, while beautiful females are killed and preserved for the Masters to admire. Slaves are furnished with breathing masks to survive the aliens' atmosphere, but are rapidly exhausted by the stronger artificial gravity and must therefore be periodically replaced.
The Pool of Fire (1968)
Will and Fritz travel to Eastern Europe, the Caucasus, and the Middle East to organize resistance against the Tripods. The resistance, having ambushed a Tripod and captured a Master, discover that alcohol has a strong soporific effect on them, and use this knowledge to simultaneously attack their cities. Having introduced alcohol into the aliens' city water systems, two raiding groups kill the Masters by forcing open airlocks and exposing the unconscious aliens to Earth's atmosphere.