I’m pretty certain you will have to clear customs and recheck in, as it sounds like they are separate flights? Are you checking luggage? Someone else can better answer on that aspect, as I’ve only landed in Madrid first when I’ve had separate tickets.
But there is a Priority Pass lounge you can use. Actually there are several, one next to where flights on Iberia for Madrid depart that doesn’t have showers, and two others that do have showers.