In short, the SR-71 was a very niche design for strategic reconnaissance, while the U-2 was more versatile.
The SR-71 is famous for its unmatched performance, but that performance came at the cost of operational flexibility. It was absurdly expensive to operate - ~$85,000 an hour in the late '80s - and slow to spin up for a mission - about 19 hours to get an aircraft ready for takeoff. This wasn't all that significant when the SR-71 first entered service, as it still was a more capable strategic reconnaissance platform than the U-2.
But times changed, and the SR-71 was left in the dust. Satellites - starting with the Corona program in the early '60s - were beginning to take over the role of strategic reconnaissance, offering significantly safer and more capable collection platforms. Despite its reputation, the SR-71 was never risked on a direct overflight of the Soviet Union in the same manner as the U-2 flights several years earlier. The same air defense network that had downed the U-2 was rapidly advancing in capabilities and could pose a threat to even the SR-71 given the right circumstances. Because of that, the SR-71 was never risked on direct flights over the Soviet Union or Flights were made over the Kola region, where approaches and overflights could happen too fast for the Soviet air defense network to react, but the deeper regions were too heavily defended. Looking at its operational history elsewhere, it becomes clear that the SR-71's usefulness was limited to niche situations where it could approach targets that lacked the strategic depth for their air defense network to make an impact. Apart from the Kola region in Russia, that left North Vietnam - where many of the more famous flights happened - and North Korea.
Compare this to the U-2. The U-2 rapidly became outpaced by air defenses and was obsolete for deep strategic reconnaissance in the span of a few years, but its high altitude flying and incredible range and endurance meant the platform could be easily adapted for a variety of other roles. Sensors would be updated on the U-2 to provide capabilities well beyond the original design. Air sampling could be done for detecting nuclear tests, a datalink would be provided and electro-optical camera system installed to allow for real-time transmission of imagery, and radars and signals intelligence collection equipment were added. The result was a platform that could safely loiter outside of hostile airspace for hours on end, looking in using obliquely-mounted cameras/radars and listening to signals and electronic transmissions over long periods. To get a good idea of what the U-2's turned into, take a look at what's being slated to replace it now - the RQ-4 Global Hawk. The U-2's original replacement was a high-speed, high-altitude superplane, but it has since been deployed more like a manned drone for long-endurance surveillance missions.
So while the SR-71 took over the U-2's initial role - reconnaissance over high-risk, high-value targets - it too was outpaced by satellites and air defenses. The U-2 was able to expand into other roles where its endurance was useful, but the SR-71 lacked the kind of loitering capabilities of the U-2 and was further beset by very high operating costs.