Hi Andrés,
I had a play with synthetic images as you did. Everything is behaving much as expected, IMO. I have done the same exercise before and got the same confusing results as last time. I think that colours can be very subjective. My wife and I certainly don't have the same sense of colour
The way the script works is by assuming that each of the predefined colour ranges is 120 degrees wide and centred on a multiple of 60 degrees (0 = red, 60 = yellow, 120 = green, etc.) This is only approximately correct, but I find it close enough most of the time. For careful work I use the cursor readout to check actual hue values in my images.
The big complication is that in reality hue isn't a simple linear thing. If you look at one of your synthesised colour images with the readout cursor you will see some weird stuff. What is the hue value at the endpoint where it should be 360 degrees? On the 0.5 chrominance image it is 359.28 degrees which is pretty close, but on the 1.0 chrominance image it is 3.2846 degrees. You may get different results depending on what colour space you are using but I don't expect them to be any less weird. Here's another weird thing: the hue values through most of the green area in the 1.0 chrominance image are all the same at 134.3887 degrees. I presume what is happening here is that the colours are being clipped to the gamut of the colour space. Take a look at the L values. They aren't all 0.5 as you would expect. Similarly, the chrominance values aren't all 1 - they vary between roughly 0.4 and 0.8.
So, to build a ColorMask script that works "perfectly" you need to take into account the intricacies of colour spaces and the varying human perception of colour. That's something I couldn't do without a lot of research and perhaps not even then. Despite being simplistic I think the script is still useful but I'd be happy to jump ship if someone builds a better one!
Hope that explains your results & concerns. If not, let me know the details including what colour space you are using.
Cheers,
Rick.