So we have to understand a few concepts to put this one together, bear with me as I lay the groundwork!
"Volatility" is a quality of a substance that basically means it gets in the air and all over the place easily[the ability of a chemical to evaporate and propagate through a specific medium.]. Our bodies can detect a lot of whole range of substance, but often volatile substances are easily detected when exposed to an environment because they evaporate and spread so readily! Think something like your mother's or girlfriends nailpolish remover! That's acetone, a heavily volatile solvent.
Another concept would be chemical decomposition! Chemicals can change in various ways, exposing them to heat, mixing with other chemicals etc. These chemical reactions done by a middle schooler might be something similar to hydrogen peroxide and baking soda together. It's an uncontrolled reaction when two reactants are put together! The human body has an incredibly complex little trick called metabolism. Metabolism is both the CONTROLLED building and breaking down of chemical structures in our body. (catabolism for breaking things down, anabolism for building larger things)
One more thing, the circulatory system. The human body has a closed circulatory system, which in essence is a highway for nutrients to reach EVERY SINGLE CELL in your body. They go from being very large, such as the aorta, to small, capillaries. But they are all technically connected and one huge highway. With regards to the lungs, there are TINY TINY pockets of air called alveoli. Each one of these sacs has a blood supply, tiny capillaries. Millions and millions of these little guys. What happens when you breathe into your lungs, the air enters these sacs and the gas can PASS THROUGH the tiny barrier of cells between the air and your circulatory system. Also, the gas exchange allows for your body to get RID of CO2. There is a HIGHER concentration of carbon dioxide in your blood relative to the air, so the carbon dioxide diffuses out into the air in your lungs.
**OKAY. Now to tie all this together.**
You get a drug injected intravenously into your circulatory system. Your body metabolises and breaks down that drug, making it into either a more useful or less harmful version of itself. One of the things that your body changes a substance into could be volatile, and when reaching the lungs from your blood supply- diffuse/evaporate into the air. From there, when you exhale- the metabolic by-products hop a ride and are exhaled along with your breath!
*There's a neat chemical experiment you can try to test exactly this, rub peeled cloves of garlic on the soles of your feet. After about 15-30 minutes you will "taste" the garlic. This is because there is a molecule called Allicin in garlic, that can be absorbed through the skin into the bloodstream. Eventually that molecule will hitch a ride up to your lungs, and as you exhale your receptors in your mouth/nose will pick it up!*
Your lungs are basically a set of sponges made to expose your blood to as much air as possible. Anything in your bloodstream that can evaporate will dissolve through the walls of your blood vessels and into your breath, including water (making your breath moist), carbon dioxide, and the metabolic byproducts of alcohol (which can then be detected by breathalyzers) and other drugs. A fraction of these evaporated compounds gets deposited in your nasal lining as you exhale, where they are detected by olfactory nerves and get reported to the brain as smell.