Even though this is an old thread, it may still be interesting nowadays for people wanting to dive in Spain. In the recent past, a medical certificate was compulsory in Spain, no matter how old you were, and you had to renew it every two years. Additionally, it had to be issued by a doctor who's an specialist in hyperbaric medicine (even though there's no such specialty in Spanish medicine faculties), not any old family doctor.
But as of summer 2020, the certificate is only compulsory if you are over 45. If you aren't, you will have to fill in a form answering some questions, and depending on your answers, they'll ask you to get a certificate or not. I think that you still need to have a new certificate every two years, though I'm not 100% sure about this. It could be one, though I don't think so.
All of this said, I'll be starting my OWD course in two weeks' time, and when I sent an email to the diving school, they told me, among other things, that I had to get the certificate, without knowing my age (and this was after it stopped being compulsory for everybody). I don't know whether they did so because they want to make sure every new diver meets the health requirements, and won't ask it for, say, an AOWD course. Because of my age, I do need the certificate, and I was going to get one anyway, even if it hadn't been compulsory for me, just to know everything's all right.