Astronomers do not know for certain. There are two possibilities. The waves could be self-sustaining in any flattened distribution of matter, or the waves could be triggered by an external agency.
The latter possibility is strongly suggested by the fact that many if not most of the most dramatic 'grand design' spirals in the neighborhood of the Milky Way can be seen to have nearby companions that are tidally interacting with them. Computer modeling shows that a differentially-rotating disk of gas and stars will develop a spiral pattern when even a small galaxy passes close by. The Milky Way has the Large and Small Magellanic Clouds to possibly serve this role. The Andromeda Galaxy and M-33 also have companion galaxies and also show prominent spiral patterns. More distant galaxies also have spiral shapes, but only in a few instances can we see signs of any nearby galaxies as small as the Magellanic Clouds at these distances.