How can I automatically delete comments that contain a URL?

Well the best way is to use a antispam plugin like Aksimet. Other captcha plugins can be helpful too, you just have to look for the captcha keyword in wordpress repository.

If you want to do this manually, I can give you a hint. First of all, you need to know which action hook you want. I couldn’t find an action that fires before the comment insertion, but comment_post runs after that.

Then you need to detect if your comment body contains a url, this SO question can be helpful with that. You can delete a comment with wp_delete_comment function.