UX arrives in T2 and LA departs from T1; you can use the SkyLine people mover to transfer airside. The Latam flight requires passport control to exit Schengen (due to the flight continuation to SCL), and they do tend to board a bit early. If you have the LA boarding pass in advance it should be doable.
Fortunately you have a backup measure if the UX departure is significantly delayed ... just stay in MAD.