The mission of NASA was always scientific from its inception.
"The aeronautical and space activities of the United States shall be conducted so as to contribute materially to one or more of the following objectives:
(1) The expansion of human knowledge of phenomena in the atmosphere and space;
(2) The improvement of the usefulness, performance, speed, safety, and efficiency of aeronautical and space vehicles;
(3) The development and operation of vehicles capable of carrying instruments, equipment, supplies and living organisms through space;
(4) The establishment of long-range studies of the potential benefits to be gained from, the opportunities for, and the problems involved in the utilization of aeronautical and space activities for peaceful and scientific purposes.
(5) The preservation of the role of the United States as a leader in aeronautical and space science and technology and in the application thereof to the conduct of peaceful activities within and outside the atmosphere.
(6) The making available to agencies directly concerned with national defenses of discoveries that have military value or significance, and the furnishing by such agencies, to the civilian agency established to direct and control nonmilitary aeronautical and space activities, of information as to discoveries which have value or significance to that agency;
(7) Cooperation by the United States with other nations and groups of nations in work done pursuant to this Act and in the peaceful application of the results, thereof; and
(8) The most effective utilization of the scientific and engineering resources of the United States, with close cooperation among all interested agencies of the United States in order to avoid unnecessary duplication of effort, facilities, and equipment."
That's one of the first declarations in the act which created NASA. While science is present, it is not the only thing present. Therefore you cannot say "the purpose" of NASA was any one thing, unless all eight of those combine to provide that one thing.
All eight combine to help detach humanity from this planet. Science is just part of that.
While I don't disagree with this sentiment, I do think it is unattainable for mankind at this juncture. It would require complete disarmament and quite a bit more social cohesion to generate the resources necessary. I doubt it could be done by one nation, even one as wealthy as ours.
I don't think it can be done by a nation. However, it can be done by people. "Unattainable" is what you tell your kids about cookie jars...it doesn't apply in the real world.
NASA didn't fail at that mission because they were never tasked with it. The missions with which they were tasked were completed, some very very well, some satisfactory, and some less so.
NASA never enforced any kind of monopoly. There have been space agencies in other lands overseas the whole time of NASA's existence. Nothing else happened in the US because there was never before a concentration of wealth in hands that wanted to carry out space science.
From the Space Act of 1958:
"(8) The most effective utilization of the scientific and engineering resources of the United States, with close cooperation among all interested agencies of the United States in order to avoid unnecessary duplication of effort, facilities, and equipment."
In other words... to be the center of a monopoly. They launched into it immediately with their private sector contractors with their patent policies. Reagan was the first to try to make things easy for commercial space operations, and there are plenty of NASA types who think the worst mistake they made was letting Scaled Composites mess around in "their" playground a few years ago.