These tests don't just incidentally assume random sampling. Instead, random sampling is what these tests are designed for.
Even if you've used careful study design to prevent all the other possible problems with a study (unbiased sampling, no measurement error, etc.), you still have to check whether sampling variability could be a problem. If you ran the study again, you'd presumably have gotten different participants, and thus different data, with different summary statistics. So, if the sampling variability is too large, then for instance you might get a positive treatment effect $\bar{x}_{meds}-\bar{x}_{placebo}$ this time but a negative effect next time, and thus you can't really trust the direction of the effect from any one study of this size.
Now, if you have a very large sample size, you'd probably get very similar summary statistics if you ran the study again. Is the sampling variability small enough that you can trust your statistics from this one study you actually ran? This question is essentially the only thing the classic hypothesis tests are checking for.
To do this check, hypothesis tests compare your actual observed statistic against a null distribution of "other statistics you could have seen if the null hypothesis were true." If you sampled your data randomly (simple random sampling / SRS, or independent & identically distributed / iid), this null distribution is straightforward to derive mathematically (or simulate computationally). But if your data are a convenience sample, then there's no clear way to derive/simulate an appropriate null distribution. If your actual statistic came from a convenience sample, it may or may not look "extreme" compared to a null distribution that assumes iid data... but that tells us nothing about how "extreme" it would look compared to other convenience samples.
Asides:
This is also why classic hypothesis tests get more complicated when you allow for "blocking" & other study-design features that minimize variance. If you know the data weren't sampled iid, there's no point in comparing your statistics against a baseline null distribution that was constructed under the iid assumption. Instead, you need to derive a null distribution that matches how your data were actually collected.0
As gung's answer points out, permutation tests can be appropriate if you carried out random assignment instead of random sampling. If that's true, and if it's a situation where the classic Z/t/etc tests are a good approximation for permutation tests, then you can use them. But you're using them because they approximate the permutation test, not because there was random sampling.