Adding what I was told by the Spanish police. (Policia Nacional)
As is my case if both parents remain married, there should be no problem with one of the legal guardians travelling alone with their child. It is important to take some manner of proof of this so I was advised to take my Libro de Familia which is a document issued in Spain to couples when they get married and contains official registration of any children they may have.
The policeman did ask if I was divorced or in the process of getting divorced and said in this case it's necessary to get a letter of permission from the other parent which needs to be validated in a National Police station before travelling.
I didn't find out if both parents have to be present during the validation visit to the police station, feel free to add in the comments if you find yourself in this situation.
Adding an edit after 4 years (unfortunately now divorced).
I was refused boarding on an Iberia flight to the UK with me travelling with a UK passport and my son who has both Spanish and UK nationality travelling using his Spanish DNI. This was because the gate employee was concerned I didn't have custody at the time, despite passing check-in, the border and security without issue. This was a routine check as there were no other events to suggest we were anything but normal travelers. Fortunately I had a copy of my divorce agreement on hand which clearly stated I had custody for the dates concerned and we were allowed to board.
On arrival at the UK border we faced a 20 minute delay while checks were carried out to ensure my son although not carrying a UK passport was entitled to one, as I had registered his birth with the British consulate when he was born. (His age at the time of this journey was 9 years old). The border force agents were extremely professional and advised me to obtain and use a UK passport for his travel to the UK in the future to avoid delays. Note that I was told during the incident at the boarding gate that this could also have been avoided if my son was carrying a UK passport.