Why did God kill akons entire family in the book of Joshua?

I'm listening to the nlt version on a Spotify podcast be read word for word, and when I got to that part id be lying if I said it didn't make me sad. I completely understand that when Akon sinned him hiding it caused Israel to be defeated right after, but his family? I can't imagine being oblivious to my father or husband doing that then being told that I'm getting stoned because of it. After they died God was no longer angry because the wages of sin is death. I understand that. But what did God get out of killing innocent people if his family didn't infact know about his sin? I just want to understand this