That depends on the messaging app you're using. Android Messages assigns a color-coded icon to each thread in your conversations list, and it seems to be arbitrary or perhaps determined by the initials in the person's name.
Or are you talking about something else?