Most early computer software was results of consulting work, which was usually done under a contract, which set conditions on the software, including on copying. The first attempt at imposing copyright on software was by North American Aviation in 1961, which submitted a tape of the program to the Copyright Office for a copyright registration. Later two other short programs was submitted by a Columbia University law student. The Copyright Office in the end concluded that a program was like a how-to book and thus could be copyrighted, provided that it was original (of course), that it had a copyright notice (a requirement for all copyrighted works back then), and if it was to be registered, that the human-readable source code be deposited.
Later the Copyright Act of 1976 made it clear it intended software to be copyrightable. But because Congress did not want to further delay passage of the bill, it appointed the National Commission on New Technological Uses of Copyrighted Works (CONTU) to report on computer programs and other new technologies emerging at this time. CONTU held extensive hearings on computer program and other new technologies and produced a final report on July 31, 1978 with several recommendations, including on computer programs. CONTU recommended adding a definition on computer programs and adding a provision stating that copying that is part of the nesserary steps for running of the program and for archival purposes provided that all copies are destroyed upon transferring the rights to the program. Congress adopted these recommendations on December 12, 1980.
As people started software companies making money on software, copyrighting software becomes more common. Thus came the invention of software licensing and software license agreements that prohibits software copying, or "piracy" as it were called, interfering with the community of software sharing. And companies kept the source code secret too (IBM created it's Object Code Only policy in 1983). Both of these made many people unhappy, including Stallman who created the FOSS movement.