I think there's some controversy over this, someone once mentioned that he used magnets by putting them in the goldfish and hiding some on his hands- but if you look at it, the goldfish really don't behave or move like they have magnets in them in the slightest

.
My theory on this: fish are intelligent. There are even octopuses with higher IQ than cats (i read anews article once on how scientists taught an octopus how to open a jar with food in it). I read another story of a guy who owned a petshop, but had problems with his fish hiding from the customers all the time particually when little children tapping the tanks.
So whenever he fed the fish, he would tap the tanks- soon the fish associated the tapping of tanks with feeding time, and so when little children tapped the tanks the fish would rush to the front to see them!
If you think about it, it makes sense for a lot of fish to have lots of brain power- for example, with Red tailed balck sharks, in the wild they have large territories which they defend against other sharks- it takes a lot of memory space and brain power to recognise every detail of your territory, all the best feeding spots, all the danger zones, all the local RTBS etc...
Guppys are also remarkably intelligent for such small fish- they can recognise not only their owner but also each other;
http
/news.bbc.co.uk/2/hi/uk_news/scotland/3009170.stm
http
/news.bbc.co.uk/2/hi/uk_news/wales/n...est/5060694.stm
I think these goldfish were probably trained somehow to do what they do