That said, I should point out two things. First, for your use-case, the water doesn't need to be pure. You're not transmuting the "element of the water" in your starting object into the "element of stone"; You're polymorphing "a barrel of water" into "a barrel-sized rock." You could similarly use Polymorph Any Object to turn "a corpse filled with daggers" into "a pure spherical crystal" and the resulting object would be entirely dagger-free;free. Impurities in the starting object don't have to be present in the end product if you don't want them to bebe; You can just choose to turn unclean water into "a rock that is pure and free of contaminants."
On the other hand, stone to flesh isn't a polymorph spell even if it feels like one, and almost that entire section is written as if polymorph spells always target the caster and not inanimate objects, so it's still a little ambiguous what happens when you try to turn a rock-that-was-once-water into meat.
Complicating this further is the fact that a permanent-duration spell isn't the same thing as an instantaneous-duration one. Even if you make the polymorph any object spell permanent, the spell is still there, actively maintaining the target's new form, and can be detected and interacted with by any effects that can interact with active spells. What happens if the polymorph any object spell that makes the water into rock is dispelled after the stone to flesh spell is has already been cast? Does the stone to flesh spell end due to no longer having a valid target? But stone to flesh is instantaneous in duration, and the target was valid at the time of casting, so... What should happen, here?