There are two standard strands of philosophical thinking concerning this issue, one deriving from Plato and one from Aristotle.
On the Socratic/Platonic model, to know the good is to do the good. Thus a Platonist would argue that if someone claims to know the good but does not do it, then they have false or seeming rather than true knowledge. So, for example, in the Gorgias, anyone who commits an injustice does not know that committing is worse than suffering injustice, but still has false beliefs about the seriousness of harm to the soul vs. harm to externals.
Aristotle, on the other hand, explains this phenomenon in terms of what he calls "akrasia" or weakness of will. He would argue that the intellect may know the good, and the emotions desire something that is not good, and a weak will or will subject to the emotions will cause someone to act counter to his or her beliefs. Aristotle believes therefore that to achieve ethical behaviour, one must train the emotions and will to ethical habits.