Why do universities fund Ph.D. students in the sciences?
A good question. Why would the school make this investment (which could be closer to $100K/year)?


As pointed out, if you are TAing/grading/teaching, you are providing services that the school charges undergraduates for.
The funding of a university is not entirely like that of a business. Some of the money is a direct investment in purely academic pursuits, especially that from grants. Educating people and doing basic research is part of what that money is allocated for.
Averaged over all the graduate students, the direct value that they provide to the university in terms of research which goes on to get grants/prestige/donations/patents is substantial.
There is a non-trivial chance that you will become a wealthy donor to the school.