I’m wondering if this could be because Spain is not a polygon; it is is several disjoint polygons.

My guess is that the osm2pgsql tool gets confused if the multipolygon relation is not sorted so as to keep the poygon segments in disjoint groups.

I’m not sure where support requests for that tool are taken, but I suspect it is not here.