It served three important purposes. (1) To persuade the governments to allow the existence of amateur radio, (2) To force the publication of technical specifications, and (3) To restrain its use (abuse?) by commercial vendors.

First, it's important to understand that radio communication is a modern creation, not a post-modern creation like the Internet. From the beginning, telecommunication and radio communication was/is an area under heavy regulations by powerful governments. Since a hundred years ago, almost all aspects of communications (modulation, equipment, content, frequencies, price, recipients), even whether one is allowed to listen a broadcast station, were heavily regulated, often under the name of national security (and commercial interests). Today's regulations still follow the same framework. Amateur radio service was created to allow noncommercial technical experimentation - encryption is prohibited as parts of the compromise made by experimenters, in exchange, Big Brothers allowed experimenters to perform noncommercial communications under greatly reduced regulations, this even includes some authoritarian regimes such as the Soviet Union. Without such a compromise, amateur radio service wouldn't even exist at all. Unless the underlying political landscape and framework of radio and telecommunication is changed greatly, such as the vision advocated by the supporters of spectrum commons theory [0], this situation will remain.

Second, what has been prohibited is not encryption itself, but all forms of encoding that cannot be understood by others ("secret code"), this includes encryption, and also includes proprietary protocols. This regulation forces all communicators and commercial equipment vendors to document the technical information of the communication protocols being used to facilitate experimentation, thus it serves as a barrier against the use of proprietary protocols that is detrimental to the community. There is only one major flaw - there are no rules about patents, and there are already protocols designed by commercial vendors that cannot be legally decoded without obtaining a patent license. Nevertheless, the non-encryption rule works well to keep all protocols open, at least, its specification.

Third, amateur radio is, by definition, non-commercial, and it's not negotiable. There is the fact that the existence of amateur radio frequency allocation is constantly under the threat of reallocation to commercial services (the latest one is 5G). And there is also an opinion commonly held by many in the community, that there's always a trend that some commercial users may choose to abuse amateur frequencies to avoid the costs of using a commercial radio service, and that if proprietary protocols or encrypted communication is allowed, there's a danger of a de facto commercial exploitation of the amateur radio service when the nature of communication cannot be determined.

So, in conclusion, encryption was originally prohibited for "national security" to allow the existence of amateur radio, and many members in the community today believes the rule is still necessary to keep the proprietary protocols out of amateur radio, and/or to keep commercial abusers out of amateur radio. Although there are many situations which encryption can be beneficial for the community, but the consensus seems to be that, even if the state allows it (which is unlikely), its threats to the community is greater than its benefits. Any argument to allow encryption in amateur radio will be faced with suspect by many that it's only a disguised attempt to introduce proprietary protocols or commercial uses.

[0] https://en.wikipedia.org/wiki/Spectrum_commons_theory