It is illegal only if you pay for the sex, and it is to protect the sex worker, so more a H&S issue than pickup a girl
Law is to protect the sex worker for getting pregnant with no person to support the child

And correct, cannot be illegal to have unprotected sex with some random person