In many ways, Jaime has played the classic villain in the series to this point. He is violent, verbally abusive, and cares little for the people around him, in fact seems willing to casually murder them if it suits him. His incestuous relationship with his twin sister Cersei adds to his loathsomeness. But he undergoes a radical transition over the course of this novel as he struggles to recapture his sense of honor. Brienne of Tarth plays a significant role in this transition. As she escorts Jaime to King's Landing, she repeatedly confounds Jaime's expectations of her. She maintains her composure through his abuse, proves herself an excellent fighter (practically Jaime's equal, in fact), never once waivers from her oath to Catelyn Stark, and embodies all the virtues of knighthood. What makes all this so extraordinary to Jaime is that Brienne is a woman, and so she defies every convention Jaime knows and every prejudice Jaime feels about women. Previously he had valued them mostly for appearance, but the unattractive Brienne proves valuable for very different reasons. Jaime comes to genuinely respect her, and ultimately to care for her, evidenced by his saving her from the bear pit.
The effects on Jaime are twofold: First, through her actions Brienne reminds him what honor is and suggests to Jaime that he need not conform to what anyone expects of him. Though he is considered despicable by many, for killing King Aerys among other reasons, he doesn't have to fulfill that expectation. Second, she seems to reveal to Jaime, or at least prompt him to see, what a terrible person Cersei is. When Jaime comes back in contact with Cersei after spending most of the novel with Brienne, he quickly has a change of heart about his sister and sees what a vain, selfish, and deceitful person she is. She is, in essence, the opposite of Brienne: valuable primarily for her appearance and little else.
Along with Brienne, Jaime's loss of his hand is the other main catalyst in his change. His sense of identity and value of himself was tied directly to his prowess as a swordsman. With that taken from him, he undergoes an identity crisis and begins to wonder what value, if any, he has left. This crisis continues as, back at King's Landing, he reads the stories of the knights of the Kingsguard in the White Book. He thinks of his own history, including his killing of King Aerys Targaryen, and doesn't like what it says of him. At that point he seems to recognize that his value was not contained in his sword hand, that even before that loss he may not have possessed the value he thought. To change his story as it will be written in the White Book, he makes an effort to act as he thinks is honorable and right. He even tries to make amends for past misdeeds, as when he frees Tyrion and reveals to him the truth about Tysha.