A record company pays for everything that needs to be done to make a CD.
There needs to be money for things like:
- recording - studio and engineer time
- mixing - to make sure all the sounds can be heard
- mastering - sorting out the final copy
- pressing - actually making the CDs
Record companies often give their artists an advance, too - money for the artist to live on while making the CD.
Getting the money back
Any profits that the CD makes helps to pay back this money.
If it is a flop, it is very unlikely that the artist will be expected to return the money.