I think Spain government has taken this drastic measure because it has seen a huge spike in gambling from young people of age 18-25 which is the future of the country being impacted by those ads and not being that effective in their society and work.Most teams in Spain are sponsored and has always been sponsored by such ventures,gambling ones and they will lose a good portion of their revenue.Spain has taken this measure because it is affecting its economy by taking a huge portion of the youth absorbed in gambling as I see no other explanation to be such aggressive in a new law.
That is an explanation however this is not the correct way to go about this, a society that prides itself on how they are so liberal cannot go around banning gambling ads, what is next? Banning alcohol ads because the young are drinking too much? The young are not going to stop doing it just because the governments does not allow advertising anymore, and the same is true with gambling, the young will do whatever they want and they will keep gambling even with this ban.
In my view the goverment is trying to prevent gambling adictions. The young have now the internet gabling that was not available before. The companies that run the sites add pretty much zero value to the Spanish economy and create many external negative impacts, namely impacting on the young´s minds. Gambling is for adults and I should add, only for responsible adults.