The decision is usually made by the cruise line in collaberation with the Captain of the ship and WHEN the decision is made depends on how predictable the storm is.
The cruise line has the difficult task of determining at which ports the ship might be able to dock; IE: where there will be room in port for an unscheduled stop, arranging for harbor pilots, tugboats, tenders if necessary etc. A lot of behind the scenes negotiating goes on in these cases. The cruise line never just arbitrarily decides to "go someplace else".
It is also important to note that the Captain of the ship has the ultimate responsibility and can override any prior decision at any time to insure the safety and comfort of the passengers as well as the safety of the crew and the ship.
I have only been diverted once out of 13 cruises. Pretty good average, I'd say.
Happy Cruising,
Michael