A cockroach is a very strange machine. Most of what we think of as the “important” bits - breathing, controlling the heart, keeping the body alive - don’t actually happen in its head.
Cockroaches breathe through small holes called spiracles spread along the sides of their body. Their hearts beat through nerve clusters scattered down their length, not from a brain controlling everything from the top. So when a cockroach loses its head - which has happened in laboratory experiments - it doesn’t immediately die. It can walk around, react to touch, and live for a week or longer.
Eventually it dies of thirst, because without a head it can’t drink. But for that final week, it’s a perfectly functional, slightly confused, headless bug. Cockroaches have been around for about 300 million years - long enough to live through two of Earth’s five great mass extinctions, including the asteroid that wiped out the dinosaurs.