The statement derives from two questions in moral philosophy.
The second question is: "is there an absolute morality or moral code external to myself?"
The statement derives from two questions in moral philosophy. The first goes back to Plato: "how should I live my life?" That is the first good.
The second question is: "is there an absolute morality or moral code external to myself?"
The statement: "it is good to be good" can be read as "I should live my life according to an absolute or external moral code".
Whether there is absolute morality or you subscribe to a social contract theory, the idea is that you do not get to decide what is right and wrong and that it is in your best interest to abide by a moral code.
Anyway, many philosophers and psychologists use the shorthand "it is good to be good" for this idea, but there are certainly some issues with definitions. For example, should I live my life according to this code because it makes me happy? What if it causes me to suffer? Can I accept the negation or do I alter what good means (as some Buddhists do)?