Short, short answer. You can generally recover damages under two theories: 1) law or, 2) equity. Law means “the statute or prior court decisions says I get some money” and Equity means “it just ain’t fair, I should get some money.” Recovery under equity requires “clean hands” while recovery under the law doesn’t.
In your marijuana example, the law doesn’t allow recovery because the contract you have entered (purchase of marijuana) is illegal and unenforceable at law. An equitable remedy like unjust enrichment (it just ain’t fair that the drug dealer gets money for giving me oregano) fails because you have unclean hands.
If you are hit in a car waiting for a prostitute, you can recover at law. It’s against statutory and common law to hit a parked car.