The official public reason for NASA having an SR-71 back when they were still flying one was for extreme high altitude atmospheric tests/experiments. No other plane (at least at the time) could fly at the altitudes the SR-71 could.
Whether that was a cover story for additional spying by the NASA SR-71 is unknown to those of us without the necessary security clearances.