No, it's not just down to stretching although I remember being told that as a kid when asking about "snake ladies" in circuses. Yes, the stretching and training is necessary but all the stretching and training in the world won't help you bend like this. Some people simply have hypermobilities (often from connective tissue disorders) and these can allow them to bend themselves into a pretzel. The stretching and training is as much for learning how to take it to such extremes as it is for learning how to do it (relatively) safely. Of course these conditions can still often lead to complications and often have other negative impacts like chronic pain, frequent bruising, slower healing and a tendency to dislocate various joints.