There are probably at least three reasons. The first is the same psychology that drives vandals and arsonists. For some people that seems to be a thrill. If that sort of person happens to know computer programming, then he or she may funnel energy into the creation of destructive viruses. The second reason has to do with the thrill of watching things blow up.
Many people have a fascination with things like explosions and car wrecks.
When you were a kid there was probably a boy in your neighborhood who learned how to make gunpowder and who then built bigger and bigger bombs until he either got bored or did some serious damage to himself. The third reason probably involves bragging rights, or the thrill of doing it. Sort of like Mt. Everest. The mountain is there and no one has climbed it, so someone is compelled to do it. If you are a certain type of programmer and you see a security hole that could be exploited, you might simply be compelled to exploit the hole yourself before someone else beats you to it.