There are two probable origins for this idiom and I think both are equally plausible. The first one is that when you spread butter on bread you are buttering it up like one would do when trying to flatter someone. The second is in ancient India there was a practice of throwing balls of butter at statues to ask for favor, i.e. buttering them up. (source)
When we use the phrase today we generally mean that extreme flattery is used to gain information or favor. It's not always necessarily a compliment.