This is from a uni course that includes a chapter about simulation, and introduces this method for random number generation.
While the theorem is about a general $f(x)$ (probability density function), it seems to me the proof assumes an uniform distribution, and therefore it's valid only for that. Am I wrong? Is this particular proof valid for any probability density function?
Theorem and proof:

Yes. In practice, the catch is that the inverse of the CDF is not known in a convenient form for some random variables.
Because this is a result widely used in computer simulation, maybe it will help to see how it works in practice. I will use R statistical software. Function
runifsamples from a uniform distribution;qexpis the inverse CDF (quantile) function of an exponential distribution.The code below samples 100,000 observations from an exponential distribution with mean 10 (rate 0.1). For such a large sample there is pretty good fit of the histogram of the sample to the PDF of the population.
Note: For this example, you can write the CDF of the exponential distribution, find its inverse, and write explicit mathematics to match the simulation.
Addendum on sampling from a normal population (per @Henry's Comment). The CDF $\Phi(\cdot)$ of a standard normal distribution is not available in 'closed form' and so neither is its quantile function $\Phi^{-1}(\cdot).$ (Thus the crucial need for printed normal tables before the computer era.)
However, Michael Wichura (1998) has constructed rational approximations to both $\Phi(\cdot)$ and $\Phi^{-1}(\cdot),$ which are accurate to the extent expressible by double precision in software. Accordingly, R statistical software uses Wichura's approximation for its
qnorm. Soqnorm(runif(m))returns a sample of sizemfrom the standard normal distribution. [That is,qnorm(runif(m))is equivalent tornorm(m)--except for minor technical tweaks.]Note: For this example, you cannot write the CDF of the standard normal distribution. While the theorem in your Question remains valid and useful, this example must remain a computer demonstration.