Evolution works by compounding small changes over time, sometimes arriving at complex systems. There is a famous canard that evolution cannot explain eyesight because the human eye is so complex, it couldn't work except in its final form. However, it's been demonstrated numerous times that cells can be sensitive to being stricken by light, and that ability can become progressively more complex. Ds9 is obviously fiction, so we could just handwave the evolution of shape-shifting away, but I don't think it is difficult to imagine how it emerges. Individual organisms mutate and pass down the ability to alter tissues, perhaps as a response to injury or disease. As this ability becomes more sophisticated, it is employed in areas not related to healing, but starts to build into other areas of their existence, influencing intimacy and habitation.
I am sorry that's not how evolution works. Small changes don't accumulate unless each of these little changes confers an advantage in survival. Mutations happen randomly but they are only transmitted to the next generation if they contribute to the individual surviving.
Like for example if a species need to run fast in order to survive then the specimen whose legs will be more adapted to speed will be more likely to survive and their genes will be passed on to the next generation.
A species that spends most of its time in a puddle of goo, isn't likely to evolve in any direction except decay.