The purpose of the law is to make it look like they’re being “tough on crime”. As for figuring out how to actually crackdown on crime, that is a tough, because there aren’t many magic bullets.
Tackling nation-wide depression could help (as depression factors into such crimes a fair bit), Denmark has a unique method for tackling depression. Depression is particularly high in schools, as we know sexual assaults are largely committed by minors, there must be some way to counter this.
Neglect / physical abuse also have a link to sex crimes, although people who have been purely sexually assaulted aren’t linked to such. This doesn’t mean it is appropriate to shame victims of abuse, simply on the premise they might be more likely to commit crimes, as some do on Twitter.
I’m not sure how spanking would tie into that as one could consider it physical abuse, although some would argue it doesn’t cross the threshold. It can somewhat leave someone faintly traumatized for a very long time however.