I'm not familiar with Madrid, but I always have the attitude that certainty trumps uncertainty. If you know when you will be somewhere, why wouldn't you arrange your accommodations in advance?
The risk with waiting is that destinations have events. These events can make a sudden difference in the availability of accommodations. For example, here in Regina, Saskatchewan, Canada, most of the time if you tried to book a room here on short notice, you could find something, but if you tried to come when we were hosting the CFL's Grey Cup (every decade) or during our annual Agribition agricultural fair, you wouldn't get a room unless you booked months in advance. There is also the possibility of some natural event causing issues; you'd be hard-pressed to get a hotel room in cities and towns near San Francisco right now, because of the wildfires they've had recently (October 2017).
If your plans have greater flexibility and you don't need to be right in Madrid but could be an hour or two away, or you want the utmost in flexibility in your plans, then taking your chances isn't such a bad thing to do. It sounds, however, like the person you're helping would be greatly inconvenienced if room availability in Madrid became a problem, so I'd strongly recommend planning something soon.