An obituary about a prominent or newsworthy person is usually written by the newspaper staff and is published for free. An announcement of a death written by a family is called a Death Notice. Newspapers charge for these notices because they frequently include the name of the chosen funeral home, thus making them advertisements.
The cost of a death notice, i.e. obituary, can be surprisingly expensive. The average cost for 20 lines and a photo is about $300. Longer announcements will cost considerably more.