Anyone who has tried to open their laptop at a café in Madrid has experienced the same thing- a server politely walking over and asking you to put it away.
Spaniards take their coffee culture very seriously, and apart of that culture is an atmosphere of extraversion and social space. This culture can make it very hard for university students or digital nomads to find a good place to work, and luckily, many cafés have begun to change their rules.
The following is a list of cafés in the city that will allow you to work at specific tables or specific times during the work week.
Unfortunately I don't think Madrileño coffee shop owners will ever let you open your laptop on a weekend, and considering all libraries are also closed, I'd suggest doing as the Spaniards do, and taking the weekend to relax for yourself <3