Everyone around Tyrion mocks and despises him, predominantly because he is unusually short and odd looking. His father is notably dismissive and favors his other children over Tyrion. In response, Tyrion is sarcastic and moody, and he engages in misbehavior like drinking too much and routinely hiring prostitutes. Indeed, as we have learned in the earlier novels, Tyrion believes he married one such prostitute, Tysha, and the aftermath of that event had a profound effect on Tyrion that influences his present behavior. Tyrion met Tysha when he and Jaime came across some men assaulting her, and they drove the men off. Tyrion fell in love with her and married her, but Tywin disapproved, and as punishment had his soldiers rape Tysha in front of Tyrion. His brother Jaime told Tyrion that Tysha was a prostitute all along and they’d planned the whole episode so Tyrion could lose his virginity. Now, Tyrion still despises and distrusts his father, and he often does things just to spite him. He distrusts Jaime as well. The event also made Tyrion skeptical that any woman could genuinely love him, which is a large part of the reason that Tyrion prefers dealing with prostitutes to women at the court. (Of course we learn at the end of the novel that Tysha wasn’t really a prostitute and Jaime lied.) For all these reasons, Tyrion is a constant outsider, despite being among the most intelligent and capable characters in the series.
By the end of the novel, however, Tyrion has changed from resigned outsider among the Lannisters to a hateful enemy of his family. In the previous book, Tyrion showed great cunning and courage in battle, and his efforts helped save King's Landing and the Lannister family. But despite his bravery and tenacity, no one in his family shows him any respect or gratitude. Tyrion feels further alienated as his father and sister heap constant abuse on him. When he is accused of Joffrey's murder and imprisoned, he isn't exactly surprised, but he nonetheless feels extraordinarily betrayed, as he had worked only for the good of his family. Aggravating that sense of betrayal is Shae's abandonment of Tyrion, which recalls for him his experience with Tysha. These feelings of betrayal boil over with Jaime's revelation that Tysha did truly love him. She wasn't with him for money but because she wanted to be, and yet his father, with no resistance from Jaime, had her brutally raped to teach Tyrion a lesson. Before Tyrion flees, he vows revenge on Jaime, then seeks his father out. Finding Shae in his bedroom, he murders her first, then his father, getting his vengeance against both.