No doubt your friends were well-intentioned and were trying to comfort you -- but comments like this usually don't help, and often it's better just to let people know we care about them and share their grief. (In any case, a comment like this isn't supported by the Bible.)
I wish I had a full answer to your question -- but I don't. I have asked it hundreds -- maybe thousands -- of times during my lifetime, often after learning of the kind of sudden tragedy that took your nephew's life. Someday in heaven we will understand -- but not now. What we do know is that we live in an evil, sin-sick world -- and one of life's realities is that tragedy is never far from us.
But we also know an even greater truth: Jesus Christ came into the world to give us hope. Because of His death and resurrection we know that this life is not all there is, and ahead of us is the hope of heaven when we know Him. Sin separates us from God -- but by His death and resurrection Jesus Christ took away our sins and has opened heaven's door for us.
May God draw you closer to Himself during these days -- even if you can't understand why this tragedy happened, Jesus' words are for you: "Do not let your hearts be troubled. Trust in God; trust also in me" (John 14:1).