Society as a whole will be better off if no one pays the ransom. If truly no one paid, ransom attacks would end. However, if you are attacked by a ransom attack, your best individual course of action is likely to pay; your paying or not (as an individual) isn't going to be the deciding factor in the ransom industry continuing, and the ransom is likely cheaper than the cost of not paying. The rational response as an individual is to pay.
You therefore end up with a suboptimal overall situation, even though everyone is making the rational choice.
One way to break out of the prisoner's dilemma is to place an outside cost on 'defecting' from the socially optimal choice; in this case, the government announces loudly that they will fine companies more than their losses if they pay. The idea is to shift the equilibrium to not paying a ransom being the logical choice, which will, in the long run, will put an end to ransoms.
Of course, it really sucks for the people caught by ransom attacks in the meantime, and requires consistent and predictable enforcement of the outside penalty.