CoreWeave Inc. said it has agreed to buy Core Scientific Inc. in an all-stock deal worth about $9 billion that will allow it to expand its artificial intelligence data center capacity.