The literal meaning of this quotation from Hamlet is that people are often hypocrites. We use an appearance of religious devotion and piety to cover the evil in ourselves. This sounds like one of the rebukes that Hamlet himself flings at Ophelia or Gertrude, but in fact, it is an observation made by Polonius to Ophelia as he gives her a prayerbook, which he wants her to read—or at least appear to be reading. Whatever Ophelia thinks of Polonius's comment, it is not lost on Claudius, who immediately recognizes himself in the old courtier's words and says that his conscience is lashed by the dichotomy between his own thoughts and actions.
The most intriguing question, however, is why Polonius should make this comment to his daughter. It suggests not only that he is encouraging her to be a sinful hypocrite, but that he knows he is doing this. Audience members will come up with their own explanations for Polonius's strange behavior, but one point that Shakespeare may be making concerns the distinction between experience and wisdom. Polonius is highly experienced and good at giving advice. Much of it is even good advice. However, despite his experience and knowledge, he is not a wise man, as he does not take the advice himself and has now come to the point where he dispenses his counsel automatically, even when doing the opposite.
As the other answers have stated, in telling Ophelia to use a prayer book as a prop to make herself look sweet and innocent in front of Hamlet, Polonius realizes that very often we cover over ("sugar" as one might cover a mistake on a cake with lots of powdered sugar) our flaws with false piety. In other words, we often resort to religious words or practices to hide our devilish evil. Also, Polonius says, this strategy works: it is "too much proved." People fall for the false religious ploy all the time.
This fits the play's theme that appearances are deceptive and that under Denmark's seeming health lies a rot. Claudius responds to Polonius's statement with embarrassment, realizing its truth. He says in an aside that Polonius's words "lash" his conscience, and that he carries a heavy burden of guilt.
Polonius's statement also foreshadows how seeing Claudius seemingly kneeling at prayer when he isn't really praying at all—what Claudius is doing at that moment is thinking that he can't repent of his sins of murder and marrying his brother's wife—prevents Hamlet from killing his foe.
In act 3, scene 1 Polonius is using his daughter as bait so that he and Claudius may spy on her conversation with Hamlet. He wants Ophelia to act as natural as possible, and so he instructs her to walk exactly where they know Hamlet will walk, and he gives her a book to pretend to be reading, perhaps the Bible or a prayer book, which would add to her sweet and lonely aura. After this direct instruction on how to be deceitful, he admits right in front of her, “We are oft to blame in this / (‘Tis too much proved), that with devotion’s visage and pious action we do sugar o’er / the devil himself.”
Polonius is saying that humans too often act in deceitful ways, for which they are to blame. Not only is he admitting that he knows it’s wrong, he is saying that this has been proven true to him before. Clearly this “wise counselor” is unwilling to learn from his mistakes. In fact, he is currently making another mistake, in teaching his own daughter such behavior. He knows how to put on a fake face of devotion (perhaps to King Claudius?) and pretend that his behaviors are pious in order to cover up his immoral motives.
One must ask, if he is putting on a face of devotion and pretend pious action to his family and to the crown, what is his actual devilish motive that he is sugaring over? What does Polonius stand to gain by proving that Hamlet has gone crazy over unrequited love for Ophelia? Perhaps a daughter married into the royal family? And why does this not occur to King Claudius? Well, it actually might. But in that moment Claudius is too busy dealing with his own guilty conscience for sugaring over his own evil behavior, as we see when he comments in an aside, “O, ‘tis too true!”
This quotation is the advice Polonius gives to his daughter Ophelia as he, the king and the queen plan to stage a "chance" meeting between Hamlet and Ophelia. They hope to determine if Hamlet's insanity has been caused by Ophelia's rejection.
Polonious demands that his daughter pretend to be reading a book of prayers even though she is waiting to encounter Hamlet. This is the "devotion's visage and pious action" from the quote. The intent, "to sugar o'er the devil himself," is for Ophelia to appear godly and innocent as she waits.
Truly, all three of the adults here could be talking about themselves. They appear to be good on the outside, but inside they are all guilty of plotting and manipulating.