All EU countries are obliged to accept any EU passport (or national identity card) right up to the expiry date stated on the document.
Even if your son had 1 minute left on his passport when he arrived at the Spanish immigration desk, he'd have to be admitted. (Obviously, it's best to actually have a passport which is valid on the return date as well, but EU law would demand that he must be admitted to Spain).