I couldn't have stated it better myself. Most of the time it start from culture, leadership and then experience etc.
I have worked on multiple projects with varied amount of technical debt. But the project with the most amount of debt happened because of poor leadership.
The guy who was managing the project was more interested in currying favor. The end result - everyone's salary was being shared across the company in un-encrypted plain text format.