Has the part about who actually did that been missed out? At what stage does it properly come up in the books? I should really read them again.
Whoever said characters are complicated in asoiaf is completely correct, this isn't Star Wars, there's no clear cut good and bad. It's a harsh world full of people willing to do what they need to do to survive.
Tyrion baits joffrey about the dagger before his wedding after he remarks on the valyrian steel sword he receives. Jaime then figures out later that he did it after hearing Robert suggest that the boy would be better off if the fall had killed him.