How are mathematicians paid to do research? How are (pure) mathematicians paid to do research? Let's say my interests lie in the foundations of mathematics and I want to do research in that area. How am I going to get paid for that in the traditional context of academia?
In the US, 99% of long-term positions that involve being paid to do research in pure math are tenure track faculty positions, colloquially known as professorships (in the US, they follow the progression Assistant Professor -> Associate Professor -> Professor). A professor is paid to teach, do research, and to a lesser extent, to do a variety of other vaguely related things that are discussed in many places on this website and elsewhere.

Professors teach and do research. It is not true that (quoting from one of the comments) “mathematicians are not paid to do research, but instead do research on the side and teach to make a living”. It is also not true that (quoting from another comment) “at some universities, research is the main job and teaching is a necessary byproduct”. Perhaps some professors have the mindset that their job is “mainly” about one or the other thing, but that’s simply a matter of personal perception rather than an objective truth. The objective truth is that professors teach and do research, and are paid to do those two things. Nothing is “on the side” or is “the main job”.

It is also not the case that (as seems to be implied by another answer) all math professors have, or need, grant funding to do their work. Grant funding is good to have, and getting it is both a catalyst for and a side-effect of career success. It can also give your salary a modest boost. But most of the funding doesn’t go directly into your pocket, and there are plenty of math professors who have steady employment and do quite well in their research without having it.

Finally, there is a very small number of mathematicians who have permanent, full time positions doing only research. Examples of places where such positions exist are the Institute of Advanced Study, and Microsoft Research. Those positions are very prestigious and rare, so hoping to land one of them is not a viable career plan.