People have been throwing that kind of disclaimer on online comments so long that they came up with the abbreviation "IANAL" back in the 80s or 90s, back when the World Wide Web was either not even a thing yet or brand-spanking-new and Usenet was king.
There are, frankly, a whole lot of absolute morons out in the world.
Sometimes those people are the ones asking for advice, sometimes they're the ones trying to give it.
Some people who will take anything you say at face value, won't verify any information for themselves, won't do any research, etc. and if they follow your advice and screw up they sometimes like to lug litigious about it.
And when they're the ones giving advice, they'll confidently state stuff that is just flat out not true and sometimes dangerous.
Hopefully you can see at least some of the ways those could be a bad combination.
Personally when I make those kinds of disclaimers, it's because I'm
-
Looking out for myself, I don't want to get sued, I dont want some asshole to harass me or dox me or ruin my reputation or anything because they followed advice I gave because they thought I "sounded like I knew what I was talking about"
-
I'm looking out for the other person. I'm not a professional and I know it, I'm warning them that they should only take my thoughts or advice for what they're worth which may not be much, and there's a real chance the person I'm talking to is an idiot.
I also feel like it kind of invites someone who does actually know better to come in and correct or add on to what I've said, and I always welcome that sort of learning opportunity.
And it can sometimes be a way to slip in a little humor if you slip in something like "I'm no octopus psychologist" or something when you're discussing the behavior of an octopus. (To the best of my knowledge, "octopus psychologist is not a real job, and that's why it's humorous, at least to someone with the same kind of dry humor as me)