They're both mandatory/required effects on a Pokemon that you own that happen at the same time, so you get to choose in which order you want to apply the effects. If you didn't want any damage added, you could apply the damage counter from Rainbow Energy first and then remove it with Healing Scarf's effect. Or, if you wanted the damage on there for some reason, you could apply Healing Scarf first and then place the counter afterward.