I was able to do this in ZRH, checked in at LHR. The agent just added my next flight manually, so I think it depends more on whether MAD allows bags to be left airside overnight (and whether the agent knows whether they allow it).
The time between your departure times is irrelevant, but since you're in MAD for less than 24 hours it should be technically possible.