Whether you need a random sample depends on whether you're trying to make inferences about a population. In some cases you might be wanting to make inferences about causal effects in a sample. With random assignment you can do the latter even with a convenience sample. (E.g., I can collect 100 students from my uni, do an experiment testing a causal effect, and then calculate the probability of observing a difference as large as that I've seen in my sample under the null hypothesis that the manipulation had zero effect).

For inference to a population from a sample, multilevel regression and poststratification (Mr P) is something that can be applied in some contexts.