The IMPORTANT thing is that you say something, not how you say it. Young people tend to get anxious about saying or doing "the right thing" in situations involving death, but it's not important. "I'm sorry to hear that" is fine.
If the death was sudden or surprising, "Oh, how terrible" or something like that.
If you actually know the person who died, even casually, and know something nice about that person, one short comment is appropriate. "Oh, how terrible. I'm sorry to hear it. She had such a wonderful sense of humor."