He was killed because he was investigating why Robert Aryn had died suddenly after he and Catelyn had received a Raven from her nutty sister Lysa Aryn saying that Robert Aryn had been killed by the Lannisters. He found a book that had all the births of the nobles listed in it; and, he found the Baratheon section in which ALL of the children of Baratheons were born with black hair and dark eyes. Cercei's children had neither.
He had discovered that the "rumors" of Cercei and Jamie's love affair were true. His real mistake was showing mercy to Cercei and her children, which gave her time to take out Ned Stark and Robert Baratheon.
“Catelyn had received a Raven from her nutty sister Lysa Aryn saying that Robert Aryn had been killed by the Lannisters”
A letter Littlefinger told her to wrote... he is the one who set everything in motion.