Does anyone know how NASA decided on what to do and what missions to follow? Was it something that was decided internally, or were missions ordered by the federal government?
It depends on the type of mission. Generally:
Scientific missions these days are decided on via the decadal surveys (for astronomy, planetary science and earth science). These are organized by the United States National Research Council. Scientists submit their proposal. A committee evaluates these proposals for their science return, feasibility etc. and recommends missions to NASA.
Manned missions are subject to political influence. Most famously, the Apollo program was born out of a presidential directive. These days, the US Congress often influences decisionmaking at NASA by writing requirements into the appropriations bill that controls NASA's budget (saying 'you have $n of budget but you have to spend it on X'). The ISS is another example.
There is some overlap between the two: flagship missions like JWST get politicized because they require a large enough budget to be politically interesting. Lots of the nuts and bolts of the manned program are left to NASA (little interference in what science is done on the ISS).