They use an API provided by The Echo Nest (which is now owned by Spotify). Although the specifics of the algorithm are proprietary, the gist is:
Preprocess all the tracks (audio files) to decompose them into collections of numerical values called features.
Songs are rated based on similarity to the seed song, both based on the features, and also based on key words and phrases associated with each song and artist. These words and phrases are collected from the web using natural language processing methods.
Add elements of randomness and variety.
You can actually play around with The Echo Nest API yourself if you sign up for a free account on their website!