Yes, if the apartment is located in Spain you will have to pay taxes even if you are not a tax resident in Spain. In case the apartment was donated, as it is located in Spain, you will also have to pay taxes in Spain.