The synthesis of opium, for instance, requires two specialized cell types, complex organelles, and hundreds of different proteins, all told requiring thousands of different genes [1]. This is all for the purpose of creating one single highly-complex molecule. This isn't something you get at easily by "playing with the same Lego blocks."
The question is, if it's not a coincidence that both poppies and a small subset of animals both go through all this work to create two versions of this extremely-specific molecule, then what's the reason?
Sure, in the end the reason will be "it's advantageous for both species," but it's still pretty mind-blowing, and I think we're still missing a bunch of steps.
Also, this is not a refutation of your point, just interesting, but complete opioid synthesis has been engineered into yeast by at least two different teams at his point: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4924617/
That is, in fact, exactly the reason.
You are of course correct that synthesis of many biological molecules has evolved countless times over the eons, but chirality of certain critical molecules, amino acids, ribosomes, all evolved exceedingly early. Once the cellular machinery is synthesizing these things, synthesis of similar molecules, one, two, three mutations away become likely across swaths of related organisms, however distant.
In short, we're all playing with the same lego bricks, and there are only so many different models possible to build with the set.