Hair is made up of a protein called keratin. When keratin is exposed to water, it swells and causes the hair to curl. The natural oils in your hair can help to protect the keratin from water damage, which is why clean hair tends to be less curly than dirty hair.
In addition, the natural oils in your hair can help to weigh it down, which can also make it less curly. When your hair is dirty, it is more likely to be weighed down by oil and dirt, which can help to create curls.