The decision to rebuild came pre-Cap in 2004, though maybe the writing was on the wall there. The plan for the 04-05 season was to be historically bad. The plan for the 05-06 team was to be near the bottom of the league. Lundqvist and the resurgent-Jagr made them change their plans. The salary cap didn’t stop them from signing Drury, Gomez, Redden, Shanahan, Naslund, Gaborik, or Richards. It didn’t force them to hold onto picks, prospects and young players, as they proved between 2012 and 2017. It’s often overlooked that, while they did go after UFAs in the late-00s, they also only traded a single pick in the 2nd round or earlier (a 2nd for Antropov) and didn’t trade a single young player until they showed they weren’t going to have what it takes to be a solid NHLer (like Prucha). Meanwhile, they developed the core of what would be a contender for a few years. It took 7 years for that core to be competitive on its own, which isn’t really all that unreasonable for a rebuild where the team is starting from a barren system and trying to compete all the while.
On a related note, you could make the argument that the 04 lockout was the worst thing to happen to the Rangers in three ways. First, it meant they never got to finish last to draft Crosby. Second, they never got a season without Lundqvist boosting them to mediocrity all on his own. Third, Jagr never would’ve gone to Siberia for a year where he reset his head and came back like the player he was before Washington.