We don't write in a vacuum. Our books don't spring onto the scene uninfluenced by any other book that has ever come before. We are all balancing atop a great stack of the literature that has preceded us.
But sometimes, we intentionally adopt an earlier work to retell, or pay homage to. I'm rereading Braless in Wonderland right now, which includes many references to Alice in Wonderland (starting, obviously with the title). Ash is based on Cinderella; fairy tales are often fodder for retellings. There are multiple retellings of Jane Austen's works out there. Not to mention Shakespeare's.
When I was working on The Secret Year, comparisons to The Outsiders were unavoidable. I wasn't writing a retelling, but I couldn't ignore the fact that there was a huge YA classic out there that had addressed some of the same issues I was writing about. It made me more conscious of some of my book's themes, about where I wanted to cover similar ground and where I was interested in taking a different direction, in focusing on a different angle.
In dealing with a retelling of a classic, myth or folk tale, the author gets to choose where s/he will be faithful to the original, and where to veer away. The author must often decide which version of a folk tale to follow, or whether to combine versions. (It's fascinating to read multiple versions of the same story, and see how they changed over time and across cultures.) In dealing with more recent works, the author often needs to consider the ground that has already been covered by existing books and decide: How is my story different? Where is the fresh plot of earth in this well-known territory? What slant would be unique? What part of this story has nobody told before?