The most common reason there would be black stuff in your hair is because of a fungal infection called "black piedra" or even fungal infections of the scalp such as tinea capitis which can cause black dots from broken hair.
Piedra is a hair disease that is caused by fungus, which causes the formations of nodules on your hair shaft.
Black piedra and white piedra are the types of piedra.
The fungus that causes piedra is Piedraia hortae.
Tinea Capitis is scalp ringworm which is a contagious fungal infection of your scalp and can result in black dots on your scalp.
The black dots with tinea capitis are often broken pieces of hair in which the hair follicle was penetrated.
Other things that can cause black stuff in your hair aside from fungal infections is hair product buildup, dandruff, sebum or even clogged pores which can resemble like or appear as blackheads.
Dried blood or even scabs in your hair could also be a cause of the black stuff in your hair.
If the black stuff doesn't go away or gets worse you might want to see a doctor.
But most times the black stuff in your hair is nothing to worry about.
Hair product residue, along with dead skin cells and oils can also accumulate on your scalp and result in a gritty or flaky appearance.
Another cause of black stuff in your hair is sebaceous filaments/comedones which can resemble blackheads and appear as dots from dead skin cells or excess oil and even melanin which accumulates and plugs your hair follicles.
The black dots in your hair can also be the space left by dead skin cells after they shed and surround your hair follicles, especially if there's an overgrowth of the Malassezia yeast.
Seborrheic dermatitis can also result in black stuff in your hair due to overgrowth of yeast.