How did NASA Langley end up with the first 737?
NASA has lots of cool aircraft. They get them sometimes when they get to the end of their life/retired, sometimes they are custom built trainers, and sometimes they are used to test research projects. You can find the full history of that particular 737 here


  NASA’s Boeing 737-100 Transport Systems Research Vehicle was the
  prototype 737, acquired by the Langley Research Center in 1974 to
  conduct research into advanced transport aircraft technologies.
  
  ...
  
  The Boeing
  737 was Langley's number one choice, however,
  since it had a slightly wider fuselage and an
  advanced, high-lift flap system. Money however, was extremely tight. The
  market value of a used 737 in 1972 was about $3.5 million, but the
  Boeing Company had one particular 737 that its sales people said they
  might be willing to sell for substantially less."
  
  ...
  
  Boeing had designated the prototype as PA-099: PA for Lufthansa, and
  099 as the last one in a block of 100 aircraft numbers Boeing had
  reserved for the airline. The prototype was never sold, however,
  because it was only certified for experimental use. With all the
  holes, wiring and other modifications that were made to the airplane
  for certification tests, bringing it up to the standards of a
  commercial transport airplane would have been too expensive. Boeing
  used the airplane for a few additional flight tests and then simply
  set it aside. '


In short, it was cheap, couldn't be used for commercial flight, and just what NASA needed. Chapter 2 in the above linked document covers the history in more depth and explains more of the nuances of the deal. To keep from copying the whole text I'll end it here.