When I read this question, the person that I think of as an example of the famous person who dies is Prince, since he just died a few days ago. So in my mind, it’s “Why is Prince so revered upon the occasion of his death while hardly anyone sheds a tear for a prostitute or drug addict?”
My answer is that someone famous like Prince has touched many millions of people with his music. People enjoyed his music, his performances, his celebrity. People found him a sex symbol. People admired his singing, his incredible instrument playing ability, his performances, his clothing and style. He donated much money to charities in Harlem but did not want to receive credit for that. Someone famous like Prince can perform or even just show up at a fundraiser and the event immediately raises way more funds than it would without him as guest. If he were to do something like donate an autographed guitar for a charity, thousands of dollars might be raised off of those donations. He was known for helping out people in his community and doing good deeds. Many, many people also profit from the work of a celebrity like Prince. Managers, agents, costume designers, stylists, set designers, accountants, photographers, musicians, the list goes on. Members of the public may remember his kindness if they met him in the neighborhood or after a concert or event.
Contrast that with a drug addict or prostitute. Not that the drug addict or prostitute is deserving of dignity and respect but the circle of people they knew and helped will almost certainly be way smaller than the circle of people who someone like Prince knew and helped.