Cloning a PC wouldn't be legal either if IBM hadn't screwed the pooch on getting the first product to market.
First of all, IBM massively underestimated the potential for growth of a microcomputer market. They held the idea that Big Iron was the only true definition of computing, and that things like the Apple ][ were hobbyist toys that would never amount to anything. They made the further mistake of assuming that if a market for 'toy' computers did start to become worthwhile, they'd have plenty of time to develop and ship their own product.
They were wrong in both cases.
When IBM finally decided to sell a PC, they were of the opinion that Apple was 6-12 months from getting a lock on the microcomputer market. If IBM couldn't put a product on the shelves by that time, there wouldn't be much point in trying.
So they tasked an engineer with the job of creating enough of a product to hold a space in the market while the designers put together something really good. Being a good engineer, he did a baseline critical path analysis, and learned that with all the forms, paperwork, and meetings, it would take something like 18 months to ship an empty box with "IBM PC" printed on it. Actually designing a computer to put in the box, shopping for parts suppliers, building an assembly plant, and all those other little details would just push the ship time farther out.
So, faced with the choice between losing a new market entirely or skirting around standard procedures, he proposed a radical plan: design a machine out of off-the-shelf parts, and contract third-party assembly shops to do the construction. That would allow IBM to put a product on the shelves within the 6-12 month deadline, but it would also create an enormous risk: anyone else who wanted to enter the market would be able to do exactly the same thing just as quickly, and just as easily. In fact, it would be even cheaper and easier for the me-too competitors, because they could skip the R&D phase and copy IBM's hardware design more or less verbatim (a process that came to be known as 'cloning').
So they built the whole thing around a chip which could only be sold by IBM: the BIOS.
The BIOS was a computer program burned into ROM. IBM held the copyright on the program, so nobody could legally duplicate that chip. But the BIOS was also tightly integrated with the hardware. Without it, the rest of the computer was just a box of random components. But those components were arranged in such a specific way that it would be hell to try to design a compatible product that wouldn't require IBM's BIOS to run. In one version of the fantasy, IBM wouldn't have to build computers at all, they'd just license BIOS chips to all the other companies that wanted to build hardware.
Then along came a company called Compaq, which reverse-engineered the IBM BIOS, and built a legally clean BIOS of their own from the reverse-engineered spec.
IBM sued, and lost. Compaq's legal team had done its homework on maintaining the 'virginity' of the coders who wrote the cloned BIOS.
At THAT point, IBM lost all control of the PC hardware market. And since their OS had also been outsourced to a little company up in Seattle, they didn't have any hooks left in the product.
So in answer to your question: it's legal to clone a PC because IBM was lumbering, stupid, arrogant, in a big hurry, and not thinking very clearly when it spent tons of money pushing a design into the market that could be ganked away from them almost overnight. In the process, they handed half of their market dominance to Microsoft (whose OS became the only thing that made the hardware a 'PC') and the other half to cloners like Compaq.