Believe it or not, there's actually a scientific reason for this that nobody told you about. Just hear me out;
Goldfish are quite intelligent Fish, despite the myths floating around out there that they're "dumb" and have a "3 second memory". It is proven that Goldfish have a memory of at least 5 months, due to a test done, and that they're quite intelligent and can learn simple tricks. They are very concerned about their health and others, and if another Fish is feeling under the weather or depressed, other Goldfish will stay with the Fish to make him/her feel better (which is why if you go to a pet store and see a sick Goldie sitting at the bottom of the tank, you'll often see healthy-looking ones sitting next to him/her). Health is the main reason that they pick up their own feces. It may look gross, but they actually do this to monitor their health and make sure all's well. It's not exactly known how they can sense if something's just not right, but they can. I hope this helps!