Not sure how the tourist tax works in Catalonia, but here is how it works in Switzerland.
A typical example is a ski resort, where in the non touristic seasons (winter, autumn) there are 500 permanent residents, while in the high seasons (winter, a bit less in summer), there are up to 5'000 residents. The 500 permanent residents have to provide, through their local taxes, the infrastructure (roads, energy, garbage collection, etc.) required for the 5'000 people in the high seasons, which is not fair. So the tourist tax is meant to correct this, a tax is due for each day a tourist spends at the resort, to finance the overall infrastructure. The hotels and rented flat owners have to collect this tax from their customers. Some include this tax in their overall prices, some others, to look cheaper, do not and charge the tax extra.