There are many reasons a WordPress site gets hacked.
Most of the time, it’s due to an insecure shared hosting environment. There might be a back door into your server somewhere, and it could be due to another site sharing your server. That’s the problem with shared hosting.
There’s tons of information out there you can find that will show you how to clean up a hack, and prevent them in the future.