We are doing the reverse of your trip. We are flying into Madrid pre-cruise, staying for 5 nights, then taking the AVE train to Barcelona, staying at a hotel at the SANTS train station for 2 nights, then taking a taxi to the cruise port. Keep in mind that you should book your train tickets online well in advance. The Renfe website is difficult to use; I recommend https://loco2.com/en/. The prices are identical.
To get to Plaza Mayor, I recommend taking a taxi. Otherwise, you would have to transfer from the Atocha AVE side of the train station to the Cercanias side of the station. The Cercanias trains are the local (suburban) trains. You can expect a significant walk (including going up or down stairs). To take the local train, you would need to take Line 1 to the Sol (Puerta del Sol) stop (4 stops) and then walk about a 1/4 mile (350m). See the following Google map: https://www.google.com/maps/dir/Madrid+-+Atocha+Cercanias,+28045+Madrid,+Spain/Plaza+Mayor,+Madrid,+Spainemail@example.com,-3.7023697,16z/am=t/data=!3m1!4b1!4m15!4m14!1m5!1m1!1s0xd42262445cdd817:0x3947f9c28d65035b!2m2!1d-3.6889689!2d40.4071782!1m5!1m1!1s0xd42287ed85fe0d9:0xd202c4f0d67625e8!2m2!1d-3.707023!2d40.4156181!3e3!4e1
Another option is to walk approximately 1.25 miles (2 Km) from the train station to Plaza Mayor. Considering that you will have luggage from a cruise, I strongly recommend a taxi.