This can have several causes. The most common causes are:
Signal voltage too low
For example, WS2812B LEDs have a signal voltage of 5V. When these are controlled with a voltage of 3.3V (as with ESP32/ESP8266/Raspberry Pi), data may not be properly received at one or more LEDs, resulting in the wrong color. This can be solved by increasing the signal voltage to 5V using a level converter.
Noise on the data pin
The data pin is sensitive to noise. This can be solved by connecting a 470Ω resistor in series between the microcontroller and the data pin of the LEDs.