There are twothree main reasons.
One is that scientists, are not professional software developers. That's true even for computer scientists, and more so for mathematicians, physicists, chemists, biologists, social scientists and so on. Not that they couldn't, most people who are reasonably clever could become professional software developers if they wanted, but most are not.
Two is that scientists are not interested in creating whatever would be the opposite of "horrible software". They are usually only interested in the results. Where this is bad is if their software contains bugs that produce results that are wrong, but close enough to the truth to seem plausible. Fortunately, many bugs will produce results that are obviously wrong. It is also bad if the software is confusing enough that nobody can declare for sure whether it is correct or not, but to my knowledge there are not many complaints about that.
And three is that scientists are often under time pressure. They might write software quickly that they know should be improved, and they might even know how to improve it, but they just don't have the time.
One thing that I really, really hope is not the reason is that some people think anything they understand must be simple and anything they don't understand must be hard. With these assumptions, any scientist writing software that nobody can understand would be assumed to be a genius, while anyone writing software that is easy to understand would be not very impressive at all. So what a professional software developer does, making software that is easy to understand, would be damaging your career in the view of these people. I really hope this is not what happens, but I wouldn't be surprised.