Well someone sat down and wrote a 1000 dense pages that probably took 2-5 years of their life. That deserves to be rewarded. Of course there are problems with professors prescribing their own books for the class etc. but when I went to school you could return that $300 book for $200 to the bookstore once the semester was done.
First, the authors make very little money on most textbooks. You would be shocked. The money is staying with the book publishers.
Second, they've started publishing new editions so quickly with only the problem sets changed (in general) so that students can't use previous editions. If you're learning on your own, you can get some good deals on older editions for just that reason.
And on top of that, they maintain their own platforms so that even if you buy them used, you have to subscribe to a service to take the tests! All of this lines up to finding as many ways to extract money from students and at interest after it's all said and done.