It is restrained by a stone placed by the god Kashima. When Kashima's vigilance wanes, the Namazu thrashes and causes earthquakes. There's more than one Namazu, each one representing a fault line near Japan.
In fandom it can be stated that this legend is why Tenshi's connection to keystones gives her the power to cause earthquakes.
It's also why the Namazu claims it is the avatar of the god of calamity, Taishi Xinchuan. It literally causes disasters.
The namazu in Touhou having no name is a reference to a LARGE number of sumi-e catfish paintings made during the 1800s (specifically after the 1855 earthquake) which were left unsigned. These anonymous paintings are called "Namazu-e".