The "Beckham Law" tax regulations were in place when he signed for Madrid. Because of that he was treated as not tax resident in Spain until a couple of years ago. Consequently he was only taxed in Spain on his Spanish earnings and only taxed on those Spanish earnings at a reduced rate (about half the normal one).
His earnings from Real Madrid were taxed at source as normal. It's other earnings generated in Spain that the tax office is chasing. The Spanish tax authorities have to prove two things - the proportion of his image rights income that was really from Spain, and that those Spanish earnings were earnings for him as an individual, rather than for his image rights company.
It's not an easy case to bring, which usually means a deal gets done outside court. Whether that's what will happen this time or they decide they need a trial as a warning to others, we shall see.