Ok, if that's settled, how about this?
No it ain't, cause they must keep at least contact with their tubes when they stretch out otherwise they would leave them every time they attack, not just "occasionally".
Anyhow, since this bit:
Armored Tube (Ex): Coral worms build tubes by cementing together shards of coral. The tube is covered with razor-sharp ridges on the outside but pearly smooth inside. A coral worm can withdraw entirely inside its armored tube to gain the benefits of full cover. In addition, the razor-sharp exterior gives the worm a spiny defense (see below). The tube has hardness 7 and 25 hit points (50 for a Gargantuan worm, 100 for a Colossal worm).
Spiny Defense (Ex): Any creature that attacks a coral worm inside its armored tube (or the tube itself) must succeed at a DC 12 Reflex save or take 1d10 slashing damage from the razor-sharp coral shards covering the tube. Note that weapons with exceptional reach, such as longspears, do not endanger their users in this way. the save DC is Dexterity-based.
In no way prevents them from attacking while inside their tube I think we're getting there...
What about the reef complex of interlinking tubes though, and changing the "built up" tube flavour to a "secreted" tube?
I'm also thinking it's easier making the coral tube HP independent of the size of worm, since the original version implies giant coral animals of different sizes share a reef and use communal tubes.
Hence:
Coral Tube (Ex): Coral worms secrete tubes of coral to live inside. The tube pearly smooth inside, but covered with razor-sharp ridges on the outside. When fighting from inside a tube, a coral worm gains cover (+4 to AC and +2 to Reflex saves) plus a +4 circumstance bonus to its AC, for a total bonus to Armor Class of +8. In addition, the razor-sharp exterior gives the worm a spiny defense (see below). A coral worm can withdraw entirely inside a coral tube to gain the benefits of full cover.
The coral tubes of a colony of coral worms interconnect to form an extensive reef. Such tube complexes are a maze of passages which open into chambers where many coral worms can simultaneously attack intruders from all sides.
Coral tubes have hardness 7 and 50 hit points per 5 ft. section.
Spiny Defense (Ex): Any creature outside a coral tube that attacks a coral worm inside the tube (or the tube itself) must succeed at a DC 12 Reflex save or take 1d10 slashing damage from the razor-sharp shards covering the tube. Note that weapons with exceptional reach, such as longspears, do not endanger their users in this way. the save DC is Dexterity-based.
Tubular Speed (Ex): A coral worm can move at a speed of 30 ft. when any part of its body is within a coral tube.
As for the speed thing, why not just give it a higher base speed than the swim speed? If necessary, we can add a note that they can use their base speed in their tubes.
The original version seems quite clear about them being speed 12" when inside their coral tubes and swimming at 3" outside it. There's no mention of them crawling as fast as a man when outside their tube. Indeed, the MCA4 version says "They move slowly (MV 3) and are only AC 8 when exposed" without saying what form that movement is - which suggests they might swim
or crawl at 10 ft. or so outside their tubes while moving at 30 ft. inside their tubes.