yes, the airlines do have strict rules regarding this. your point of arrival AND departure on your ticket i assume is on iberia via barcelona. i am sorry to say that this means to use this ticket you must arrive and depart from that point.
if you are traveling to barcelona through madrid as you indicated, look on your ticket and see if it allows a stop-over. this gives you a chance to stay in the en route city (in your case madrid) for a few days before you land in barcelona. you may have to pay a small fee to excersise this feature. if your ticket does give you this option you'll want to contact iberia for the details.
unfortunetly if you are without this choice, you're bound by what the ticket is set for. the only way to do as you wish, first stay in barcelona for a few days, then off to madrid and depart from there,would require you to change your ticket. the airlines will charge you a hefty service fee for doing this. they now have to issue you a new ticket, or they'll require you to purchase a new one.
for future reference, it is quite common to book a flight arriving in one city and departing from another. in my experiences the cost of the ticket is generally quite a bit cheaper if you opt for this. you'll want to take this into consideration on your next trip.
good luck and have a wonderful time!!!