I was just reading about how some people, when eating squid, have ended up with squid spermataphores in their mouth. Apparently, it is painful (and not that appetizing for me). I am wondering how to prepare squid so that this part is removed. Can this also happen with octopus?
Based on the article SAJ14SAJ linked to in the comments, in the only known case in which this happened with cooked squid, it was parboiled, and almost certainly not fully cooked: "the whole squid spent just a few seconds in boiling water". If the squid is cooked, then the spermatophore will be inactive, and nothing bad is going to happen. (Living things tend to stop moving once they're cooked and dead.)
If you're trying to completely safely eat raw squid, I expect you need some squid anatomical knowledge which I don't have, so you'll want to wait for another answer.