There are quite a few reasons behind this. Here are what I think a few are; 1) Out of interest. It's fun to create a computer program. I personally enjoyed making a game. Some people enjoy making viruses and seeing if it works. 2) Some people just enjoy messing with people, either in jest or maliciously. There are viruses which only do something fairly innocent like showing a message. Then there are ones which will mess up things on your PC. 3) Profit. It's possibly to harness people's processing power for things like generating bitcoin I hear. Another is to send out spam. Another method is stealing financial details directly.