The lyrics were inspired by The Master and Margarita, a book by Mikhail Bulgakov. British singer Marianne Faithfull was Mick Jagger's girlfriend at the time and she gave him the book.
https://www.songfacts.com/facts/the-rolling-stones/sympathy-for-the-devil