How many times have you not heard someone say: "It works! I don't know why, but it works!", or: "It's not stupid if it works."?
Many times, with a misplaced sense of pride attached to it.
While it can happen for objective reasons such as meeting a short, non-negotiable deadline, it is usually the result of a deeply ingrained habit among developers, that of considering working code, satisfactory code. Ignoring, in their way, readability, maintainabiliy or efficiency making it hard to collaborate and iterate for everyone involved.
The solution is to make refactoring a mandatory part of the development process for you or your team. Strictly adhering to the boy/girl scout rule can also be a good measure to increase one's awereness over own codebase contribution.