The same reason gambling is. No, I'm serious. Theres a psychological phenomenon where things which are reliably positive are less enjoyable (or addictive) than something that is disappointing sometimes and positive other times. Writing software is like that in that things don't work, then they don't work, then they still don't work, then suddenly they do.
What you are describing is more about the frustration tolerance: In SW, you need to have a very high one, while in Gambling the addiction keeps you at the table -this is also some type of frustration tolerance, bot not the one as in a context of learning-new-stuff.