All known organic life shares something close-enough to a common ancestor that it all has a common set of inherited low-level intracellular signalling machinery based on very simple chemicals (e.g. sodium, potassium, calcium; nitric oxide; purines; etc.) All complex life (e.g. both prokaryotes and eukaryotes) shares some higher-level signalling machinery as well—even bacteria have dopamine receptors!

In higher lifeforms, e.g. animals, some of these intracellular signalling chemicals have been repurposed to become intercellular signalling chemicals within specific tissues. However, these molecules continue to act as intracellular signals within cells; it is often the reaction of the cell to the intracellular stimulus that is perceived by a larger group of cells as the intercellular stimulus.

Animals have developed advanced tissue isolation, circulatory, and xenometabolic mechanisms to prevent parasites and predators from injecting these "intercellular but actually intracellular" signals into arbitrary places in the body, because—sort of like every microcontroller having JTAG pins—every cell is "listening" for these signals, and might do something stupid/unplanned in response if the body wasn't evolved to ever emit them into such tissue. Best to put up some firewalls to hide all these open ports. This also allows you to use the same signal to mean different things in different componentized tissues (e.g. how serotonin acts in the gut vs. in the nervous system.)

But these firewalling mechanisms, e.g. the blood-brain barrier, are themselves simple, inherited from pretty early on in the multicellular tree of life. So they mostly just block the simple, active forms of these molecules—the ones the body uses itself.

So, in other words, for an organism to evolve a novel poison, it just has to take its own signalling molecules—which it already knows how to make, and shares in common with pretty much everything else—and then evolve some enzyme that "tags" that molecule in such a way that most evolved barriers won't stop it, and also in such a way that it will either break down on its own, or will break down in response to other molecules floating about in the target area, back into the signaling molecule. Boom—toxin.

It's also pretty easy to take the gene you use for creating a signalling molecule, copy it, and let the copy mutate so it now produces a deformed version of the signalling molecule—one that locks into the same receptor, but either doesn't activate the receptor, or is excitotoxic to the receptor, or isn't recognized by the various -lyzes and -ases which organisms evolve to garbage-collect signals.

Keep in mind, most of the time, these kinds of poisons will be maladaptive, because the produced toxin will end up attacking the host's own body; but if the gene happens to only get expressed in tissues of some gland (e.g. the salivary gland), then it has room to evolve into a venom.

Evolving to be poisonous is a bit harder, I think; it needs to coincide, or maybe be preceded by, the evolution of a barrier to similar toxins, e.g. skin that won't absorb the poison produced by your own sweat glands. Most poisonous animals probably preyed upon another poisonous or venomous plant/animal at some point, and evolved the defence first, before either harnessing that toxin from their food, or evolving something similar themselves.