By the same logic, shouldn’t it be illegal to hand over your wallet if you get mugged?
Companies aren’t really paying this money by choice, they are paying it because losing systems/data can in some cases result in an inability to operate - otherwise it wouldn’t really be a ransom.