It is not enough to create the segmentation node but you need to also add to the scene. You can use slicer.mrmlScene.AddNewNodeByClass to create a node and add it to the scene in one step.
I thought we don’t need a scene when we run from a script, I was wrong.
slicer.util.loadVolume loads file as scalar volume, while ImportLabelmapToSegmentationNode expects a labelmap volume; you need to use slicer.util.loadLabelVolume instead
I guess this is the main cause of the error.
It works now thanks for investigating the error.