This seems like something that should be true, but I think I remember seeing a Mythbusters episode where they decided it didn’t make a difference. That show was more about entertainment than science, so I wondered if there was a more rigorous study done? I’ve definitely seen splashes of water(?) come out from flushes so that alone seems to argue for closing lids.
Toothbrushes were mentioned, and I’d assume that the toothpaste does a good enough job at killing bacteria that it doesn’t make a difference, aside from that the bacterial load is probably low enough to be negligible.
But yeah, you don’t want to be thinking about putting a pooey stick in your mouth either.