Peeta experiences the extremes of behavior conditioning in Suzanne Collins' novel Mockingjay.
Peeta undergoes the largest transformation at the hands of the Capitol when they "highjack" him, a "secretive...form of torture" that is a "type of fear conditioning" (180). Prim asks the question that had been plaguing Katniss' mind:
"Is that what they've done to Peeta? Taken his memories of Katniss and distorted them so they're scary?" (181)
Although Katniss and Prim both want rehabilitation for Peeta, it is Delly, their classmate from District 12, who comes up with the solution to restore Peeta's mind. In what becomes a reverse-highjacking, Delly works with Peeta to help him connect to his good childhood memories and understand what is real in the world around him.
When Peeta states that he "can't tell what's real anymore and what's made up," Finnick advises him just to ask. In a game that becomes "Real or not real?" Peeta attempts to decipher his feelings and nightmares.
Peeta's personal fortitude and the aid of those closest to him, like Delly, Haymitch, and Katniss, help Peeta to overcome his reconditioning and redefine himself for the future.
Peeta really never changes.
I believe the Capitol had a hard time with torturing him, though the hijacking is ridiculously shattering, making him a mutt designed to kill Katniss.
That Peeta survives, still tries to protect Katniss, and protect anyone - and even when they torture him and he is rescued, he still tries to figure Katniss out - highlights his core power beautifully. Peeta's compassion grounds him and is what makes him exemplary to everyone he touches, and Panem. If he had become bitter - he would cease to be 'Peeta'. Peeta is the epitome character of self-sacrifice in the books - and the one who lost everything.
Finnick hit the nail on the head when he said to them, that Peeta is the only tribute that won the Games [alongside Katniss] out of compassion. He played the Game differntly. Peeta has always been hard to figure out - his core strength is in his simplicity, his kindness to everyone and his way of making people feel something of themselves by just his demeanor and his sincere artistry with words. This continues to emerge progressively as he is recovering.
It is what makes people believe in him and support him. His team mates on the Capitol mission that came up with the "Real or No Real" game that became progressively successful in him making sense of his memories and who he is; in reinforcing Pollux's bravery through their routs underground by telling Pollux simply that he has become their greatest asset by his work underground as an Avox; and by instilling hope into the heart of their shopkeeper ally / former stylist - when they gifted her a can of salmon and he told her that one should never underestimate the strength of a great stylist.
Peeta is rude to Katniss and angry at Haymitch, because he is human. Peeta needed a vent and he feel betrayed by them. Despite him never wanting to harm a soul, much happens to him - he lost his family and had nothing to return to except to Katniss, whom the Capitol painted red for him - he was still thoroughly confused and on the mental verge of losing himself permanently. Peeta even accepted to be killed off, after he saw a replay of himself going "mutt" and killing off a team member while on the Capitol mission. This was a big trigger into putting things into perspective about him.
If Peeta was not that strong, that compassionate, and had the will that can only be branded 'Peeta', he would not have survived, or would have survived only as a void shell. Peeta until the end, remains and exemplary optimist.