The documentation for MFnMesh::createColorSetWithName() says
This operation will only work when the MFnMesh refers to a shape.
I never understood what that meant. I now guess it means that you can't use that function on an object which is the output of a deformer node. There must be some way to do it, since I assume it's possible to create a custom node which adds a color set to its input, but I've never had to do it.
Sorry, that's probably not any help. It might trigger a brainwave for someone though.