purity does and doesnt matter sometimes, it depends on the drug, and the impurity. cutters are sometimes fine and are used to either give your compound a more manageable mass, better physical qualities (like melts easier without burning/lower temp smoking), or just rip people off as is the case with MSM.
Then theres byproducts/side/decomposition products, where the drug was not purified, because the inactive byproducts usually taste/behave almost the same as the drug anyway, its like the perfect cutting agent. Hypothetically if one could produce the L-isomer of methamphetamine without a ridiculous amount of cost/effort/skill, it would be the ultimate cutting agent for D/D-L racemic methamphetamine, or, ice specifically where large clean crystals are a sign of quality. technically L-meth is a side product, it has an identical chemical structure, its just a mirror of D-Meth.
Off hand i dont know any other inactive products of drugs that are produced though other than some of the re-arrangements of meth because they show up pretty often in literally any study done on street meth quality and the products are so diverse they can even be used to ascertain the entire synthesis route (useful for addressing restrictions based on whats actually used domestically). Stuff like benzyl amines, or phenyl amines, and possibly propyl amines. They would form in the final reaction under modified conditions, (fucking things up/wrong ingredient ratios/unbalanced reaction).
Now, when/why are these bad?
in the case of MDMA, i believe that it is smokeable, according to a friend, but dirty pills char readily and destroy the product by whatever mechanism you might imagine. very pure MDMA however can in principle be smoked to completion.
But MDMA also has another case, MDA, with an MAOi this can be deadly. for certain people, with certain doses, it can also be a pretty bad time, its just a fairly dangerous chemical compared to MDMA. the effects are usually close enough especially taken together. MDMA can be made from MDA, which in turn is more easily produced than MDMA in some circumstances from less of the same/similar ingredients. In short this impurity present could, and does, kill people. And it could be present due to shoddy production, or as a cutter though i think thats less likely.
In the case of DMT, the effects are extremely short lived, and not only that, the concentration in your blood from a single breath/dose directly influences wether or not you even experience anything at all. DMT comes from plant extracts and often contains a lot of difficult to remove very similar compounds which can dilute the smoke enough that you cannot physically smoke enough quickly enough in say, a pipe, to see breakthrough effects, either because the fats/resins wont release the DMT fast enough, or they are just so harsh it doesnt work, and the heat needed to push it forwards would also possibly burn the DMT. Its pretty common to see people complain about their ejuice carts with dmt not working, it needs to be quite concentrated and the vaporizer moderately good. sometimes the DMT wont even dissolve because its so close to the limits of what various vape juices can hold.
DMT requires a clean product and/or technique to use properly.
Sometimes impurities are also chemically active, and will react at high temperatures with a given drug, degrading it, which is the simplest answer.
Context matters for each drug and route of administration. Impurities can be filler, they can affect the quality of the high, they can be toxic sometimes, unpleasant, or force you to consume more actual compound than you need for a given effect, which even as little as 1% in DMT can do, doubling or trippling doseage.