How are t-quantiles and $\chi^2$-quantiles actually calculated? I find it difficult to find a formula.
For example, the t-quantile for 0.975 and 50 degrees of freedom is approximately 2.
This is easy to find out if I look it up in a table or use software. But how is it calculated?
When I try to figure it out by searching, I always end up on a page describing that it has something to do with one's data set, but that must be something else than what I'm looking for, since the quantiles are always the same and has nothing to do with one's data set.
The PDFs and CDFs of Student's t and chi-squared distributions are known and are displayed in the corresponding Wikipedia articles. The PDFs are shown in appendixes of many intermediate probability and mathematical statistics courses. Your specific questions involve use of the quantile functions (inverse CDFs). In principle, methods of numerical integration can be used to get probabilities from PDFs. Also, mathematical methods can be used to invert CDFs for the same purpose.
An important computational difficulty is that the PDFs and CDFs of Student's t and chi-squared distributions are expressed in terms of gamma functions, which must also be evaluated by numerical methods.
You are correct that printed tables give results for Student's t distributions that arise in most practical applications--and for chi-squared distributions in many practical applications. Statistical software packages (SAS, Minitab, SPSS, R, and so on) have functions that give a wider range of quantiles than you will find in tables. Statistical calculators and Excel give useful approximations.
Chapter 26 of Abramowitz and Stegen (PDF file available online) catalogues some rational approximations that give reasonable accuracy over various ranges of parameters. However, these are less frequently used nowadays because it is easy to get more accurate results from software. (Some software functions use carefully vetted rational approximations, but generally more intricate and accurate ones than you will find in A&S.)