Of course, had it chosen to form a Red-Red-Green coalition in 2005 or 2013, this could have invited a backlash if the government was seen as too extreme, and there is no guarantee that its relationship with die Linke would have been stable and productive, given that it would have been a 180-degree U-turn from the Schröder years. And that's IF they managed to agree to a government deal at all in the first place.
Perhaps if it had emerged as the largest party in 2005 and the CDU made the junior partner, the roles may have been reversed. Who knows.
To be honest my argument in favour of a SPD-Linke-Grune coalition in 2005 (or 2013 but that one is harder and arguably undemocratic but still doable) is basically what happened here.
There are lots and lots of clips of Pedro Sanchez arguing "I will not do a coalition with UP"; "I will not make talks with Bildu"; "There will be no deals with the Catalan separatists", etc.
What did he do? He did a coalition with UP and did talks with Bildu and the Catalan separatists.
Of course the opposition uses those as attacks, yet the attacks don't really seem to stick all that much.
Hindsight of course, but Pedro Sanchez learned the lesson from the German SPD and the Greek PASOK; and he learned it the hard way after the 2016 Spanish election. A coalition with the far left is always going to be the lesser evil electorally. A coalition with them might hurt your polling numbers slightly. A coalition with the centre-right will sink your party forever.
Current Spanish polling does reveal that those decisions were unpopular, even among PSOE's electorate; yet the party is still polling decently well and has completely defused the possibility of UP beating PSOE. Meanwhile the fact that Grune will beat SPD is essencially a certainty now.