Madrid is really too large a city to be a day-trip destination from Barcelona. You can take a look at the train schedule on the Renfe website. The shortest trip is 2-1/2 hours on the AVE. Both Barcelona and Madrid have rather large main stations, so you'd need to allow time at the beginning of each leg to find your way to the correct platform. And once you reach the end of the train ride, you still need to get to the sights you want to see or back to your hotel. All in all, I'd expect the round-trip to take about 8 hours.
If you decide you do want to spend a few nights in Madrid, you'll save a great deal of money on the AVE tickets by making the purchase very early. Buying on the day of the trip could cost you 120 euros each, or perhaps even more. That's one-way. Buying at the beginning of the sales period would probably save you more than 50% of that cost.
Madrid is a good destination for people who are interested in its three important art museums and/or the Palacio Real and those who have the time to take in some of the really wonderful surrounding cities (Toledo, Segovia and Cuenca being my favorites). If you aren't much interested in art, I don't think it makes sense to go to Madrid in order to head right out of town to other cities. Barcelona, frankly, is more immediately engaging for most tourists. If you want to see a different city, you can reach the charming Girona in about an hour. Or you could venture to Montserrat. Enric created a special thread no long ago in which he goes into considerable detail about visiting Montserrat.
To check flights from Spain to Sicily, I suggest using skyscanner.com/
Edited to add: The Catania airport has more flights than Palermo. Some travelers fly into one and out of the other in order to eliminate some backtracking. I randomly checked the month of April 2017 and found that there are some non-stops into both Catania and Palermo from both Barcelona and Madrid (not necessarily every day). Fares vary a lot, so check your planned travel date right away.
Read all the airline's rules carefully to avoid really unpleasant surprises like baggage fees and departures from an airport that may be nowhere near the city you're in.
When is your trip, and how much time will you have in Sicily?