Since everything is on the same itinerary, it's LATAM's (assuming you made the purchase with them) who's responsible of you making it on time. If you miss the connection (which I don't think you will... I've made it from T4S to T4 in rush hour in less than 20 minutes most of the time) LATAM is responsible for putting you on another flight at their expense.
That said, Before your arrival into MAD, talk to the crew of your inbound flight and explain that you are on a really tight connection and you'd greatly improve your chances of making the outbound flight if they let you off the plane quickly. Most of the time crews are accomodating and will move you as close as they can to the door so they can let you out quickly so you get to immigration ahead of the rest of your plane companions. That usually does the trick.
I can't seem to remember if you will need to go through security again, as you will remain airside.
As long as your inbound gets to MAD on time, you should be OK.