Yes, ghostwriters are legal. It is a legitimate and ethical practice between the 2 (writer and the client). The writer agrees to write the content for the client and transfer all the rights and ownership to the client upon completion, while the client agrees to pay the writer a fair fee for their work.