There are many reasons. They include money, intellectual property, regulations, and Elon Musk.
Money. Building open source software is relatively inexpensive, sometimes ridiculously inexpensive. No equipment is needed as most programmers have their own computers. There are many open source software projects where the developers do their work for free. Occasionally commercial companies will release some of the software developed in-house as open source, sometimes as a benevolent charitable pay back for all of the open source software they use freely, sometimes in the hopes that external developers will enhance the product, for free. As an example in the space exploration industry, Ball Aerospace made their COSMOS software open source.
Building rockets on the other hand is ridiculously expensive. This is an endeavor that requires very expensive equipment, very expensive facilities, very expensive parts, and rather expensive employees. Elon Musk started SpaceX with \$100 million of his own money. When he showed that he might know what he was doing, he received a downpayment of what would eventually be almost \$400 million from NASA.
That huge investment from NASA was made without NASA getting a stake in the company. NASA was looking for alternatives to the broken cost-plus contracting mechanisms that NASA traditionally used to build new rockets and new spacecraft. That investment was however made with the requirement that the companies that participated in the Commercial Orbital Transportation Services (COTS) project had to obtain significant amounts (hundreds of millions of dollars) of private financing to show the companies had skin in the game. SpaceX did so. Rocketplane Kistler did not, and their COTS contract was cancelled; that company eventually collapsed.
Elon Musk did not use a hundred million dollars of his own money to start an open source project, nor did those private investors.
Intellectual property. One of the key assets of any technology company is its intellectual property, and SpaceX has a lot of intellectual property (IP). Those private investors would have invested zero dollars in SpaceX had Elon Musk said that all of the SpaceX IP would be placed in the public domain.
Regulations. Even if Elon Musk did want to put all of SpaceX's IP in the public domain, there are multiple regulations that would have prevented him from doing so. The US government views rockets capable of going into orbit as advanced weaponry. The International Traffic in Arms Regulations (ITAR) and Export Administration Regulations (EAR) place severe penalties on companies and individuals who release restricted information to other countries, including countries that are US allies. The penalties on companies involve massive fines. The penalties on individuals involve large fines and substandard government-funded room and board (i.e., prison.) Hosting the plans, schematics, flight software, etc. for a rocket on GitHub would result in people going to jail.
Elon Musk. Elon Musk is a strong personality. He does not believe in patents, which is a way of open-sourcing an idea (with a fee). He instead wants SpaceX and Tesla to guard their IP as trade secrets. Musk organizes his companies vertically rather than horizontally as this gives those companies much better control over the supply chain and much better control of its IP. There is no way Elon Musk would have thought for even a second regarding making SpaceX an open source project.