Here's important part from anarekist's link about how that toxin is produced:
It was a mystery why such a diversity of unrelated organisms would all evolve the same toxin, until it was recently discovered that bacteria associated with many of these animals actually produce TTX. This is the case in blue-ringed octopuses. Their salivary glands harbor dense colonies of TTX-producing bacteria. The blue-rings have evolved a symbiotic relationship with the bacteria, providing them ideal living conditions while using the toxin they produce to subdue prey and as part of their highly advertised defense.
.