the MaterialID works with a random function, so the colors can change.
To have a more solid control over the mat id , you can use the Object layer color pass instead.
assign an object tag to all the objects or group of objects, then, with all the tag selected, in the Object layer tab, you need to right click on the Object color name, and choose User interface/Show sub channels: then type
rnd(100)+num
in all the three color fields to have different colors that do not change: