I should note that this answer is going to focus on the research-based Doctor of Philosophy (PhD) degree and ScD equivalent This answer does not apply similar degrees in other fields (e.g., EdD, DBA, DrPH, etc.) since the motivation for those is much more field dependent.
First, lets start with the obvious, you get a PhD because you want to teach at the college level. Barring the Professor of Practice which requires significant industry experience, the PhD is the minimum requirement to get a tenure-track position. There used to be some fields such as nursing that were the exception to this, but they are now converging on PhD requirements. Despite the general oversupply of PhDs as well, some fields are actually facing shortfalls.
Another reason to purse a PhD is because you are hoping to purse a career where it is advantages to have one. Consulting is a good example of this, most Chief Science Officers also hold a PhD as well. There is increasingly a perception that PhD is required to work in policy in Washington, D.C. Furthermore, despite the ongoing perception that a PhD isn't valued by industry, private-sector R&D labs are staffed by PhDs and industry investment in R&D is growing.
Of course, these lead to a very salient argument against getting a PhD due to the time investment leading to monetary loss in the long term. Generally this is irrelevant if someone is dead set on a job in academia, you have to get the "union card." There is more risk involved if you are planning on going into industry since in theory a Masters should be enough. This does lead to some PhD applicants who intend on dropping out once they get their Masters. These are generally rare though. Thus, some, likely most, people get a PhD because they want a career in X and the PhD will make them competitive for that career.
There is a common perception that people do a PhD because it is "next." Although a survey of UK students indirectly supports this for applicants without an employment history, it does not for those with one. Generally the most common theme seems to be "intellectual curiosity and interest," even more so among older applicants. In fact, I would argue that the admissions committee should filter out people that are just doing it because it is "next." PhD programs are not easy and have attrition rates that exceed 50%. Things may not be easy for those that leave (e.g., one, two). Intellectual curiosity and interest in what you are going to spend a couple years of your life is important. For funded PhD students (don't get a PhD without funding), getting into a program means someone is going to pay you to do a very deep dive and learn something that wasn't know before. Factor in the fact that the odds are very low that you can do this once you enter industry or government and for those with the intellectual curiosity and interest it doesn't take much to at least apply for the PhD.
Finally, a note on financial compensation. In the United States the average salary of a new assistant professor (tenure track) is $65,372. The starting pay for STEM is highly dependent upon your field but the range seems to be $55,087 to $64,891 for a Bachelors and $72,080 to $73,871 for a Masters. So on the face of it the professor isn't as highly paid; however, that's just raw compensation for 9 months work. Soft money or consulting can result in higher pay during the summer and the costs associated with attending conferences usually isn't factored into the compensation as well. So doing a direct net compensation comparison can be quite difficult. Also, putting a financial value on surviving the PhD and spending the time pursing intellectual curiosity and interest may be impossible.