According to this article, the flight had a problem with one of the landing gear doors not properly closing. This caused too much fuel consumption to reach the destination airport. In such a case, an alternative landing airport is needed, but there is no urgency to land as soon as possible.
22 minutes after take-off the aircraft started its turn back to the departure airport, far from the halfway point between Barcelona and Malaga.
It is not uncommon for airlines to return to the departure airport instead of landing at the nearest airport in case of an in-flight failure. In this case, I can imagine that Vueling have more maintenance expertise at their biggest home-base Barcelona than at either Valencia or Tarragona.
They can repair the aircraft or make a replacement aircraft available to execute the flight with a few hours delay, or offer alternative flights to Malaga. Either solution will likely be quicker from Barcelona than from the other two cities.
For some passengers the trip to Malaga would no longer be needed after three hours delay (e.g. those that were flying there for a short meeting). For those passengers being back in Barcelona is better than being stuck in either Valencia or Tarragona.