As said above.
Unless you have already a specific place for lunch, if I were you I'd do as follows: take the train from the airport to Barcelona-Sants, leave your luggage at the "consigna" at the station, from there, there are quite a number of places for lunching a stone throw away. Depending on the time availability you could venture a little farther (or not). When leaving for Madrid you're going to do so from this station.
At less than 10" on foot, there's https://tdk.cat/ which I personally like, it offers a great sample of local traditional Catalan cuisine. If you go Mon to Sat at lunchtime you can have "menu del dia", which is very cheap and worth taking advantage of. There are plenty of others in the area, as I said, such as https://ca.lateregastrobar.com/ or https://www.lamundana.cat/ And if you fancy something lighter, such a tapas lunch, definitively https://www.elcellerdelnoupriorat.cat/tapas-i-platets/ which offers lots of tapas with local products: cheeses, seafood and meats.
Enjoy!