We know that Tanjiro’s family gets killed by a demon. At first, we’re left in the dark about who did it. But as the story goes, Tanjiro figures out it was Muzan Kibutsuji himself who killed his family. He recognizes Muzan’s scent – the same one he smelled at his family’s house after the attack.
But Why did Muzan do it? Was he targeting Tanjiro’s family on purpose, or was it just random bad luck?

Muzan’s always trying to make a demon that can handle sunlight. He’s been turning people into demons for ages, and trying to find one of them who won’t burn up in the sun.
When Muzan attacked Tanjiro’s family, he was probably just doing his usual thing; making more demons to add to his collection or, there is a possibility, Muzan might have attacked Tanjiro’s family due to their connection to Yoriichi. Way back in the day, there was a strong demon slayer named Yoriichi Tsugikuni who really beat Muzan, but Muzan managed to escape.

Yoriichi has connections to the Kamado family. So, Muzan might have attacked to get some twisted form of revenge on Yoriichi’s memory. But it’s just a theory. It’s not confirmed in the anime or manga.
Muzan didn’t know it, but by attacking Tanjiro’s family, he created a strong enemy for himself. We don’t have a clear answer on why Muzan killed Tanjiro’s family. It could’ve been just another day of demon-making for Muzan, or maybe there was some reason tied to Yoriichi. Either way, this attack starts the whole “Demon Slayer” story, It sets Tanjiro on his path to becoming a demon slayer and facing off against Muzan.