The use of the word “illegal” here is essentially bullshit. It is a hangover from fifteen years or so ago when people who had never, or scarcely, even been on the internet were panicking about all the terrible dangers this strange new medium might pose to our young people.
To be fair, back in those days people selling online porn were a good deal more aggressive than most are now about trying to get people to quite inadvertently click links to their sites, and about preventing you from closing the sites once you got there. Most, though not all, pornographers seem to have learned since then that such tactics are ineffective and counter productive.
Even back in those old “wild west” days of internet porn, I think it was probably very rare for the clicking of an apparently innocent link to take you to actually illegal porn (illegal in the USA, anyway). Certainly it never happened to me, though I saw plenty of legal (and sometimes nasty) stuff that I wasn’t really looking for. Today it is almost certainly never going to happen. No doubt there is illegal porn on the net, but it is going to be well hidden from the casual surfer (and, indeed, from Google). The last thing they want is law enforcement, or someone who might report them to law enforcement, stumbling over it. If you could just Google for kiddie porn (which you could if there were open links to it scattered around), the police would do so, and then take down the sites and arrest the owners.
Of course even perfectly legal porn could get you in trouble with your wife or your boss, if they find it on your computer, so the advice is not entirely pointless. There probably still are some disguised, stealth links to porn out there,and still some porn spam (though I think both are a lot rarer than they once were), but mostly, there days, where people visit porn sites it is because they fully intend to do so.
Ransomware is another thing again, as Jophiel explains. I have experienced it once myself, when intentionally visiting a porn site. The porn in question was a bit gross, and rather more so than I had actually been expecting or hoping, but I am pretty sure it was not actually illegal (and it certainly did not involve children). Ransomeware does not rely on using actually illegal porn, it just relies on you having, at some time, having looked at stuff that makes you feel a bit guilty, which, for a lot of people, might include some really quite vanilla stuff. The ransomware message I got did not even specify that it was about porn (though I got it from a porn site), it said that I had either been viewing illegal porn or downloading or sharing copyright material. They are just using a scattershot approach in order to scare you.