If someone sells 20% of their company for a $500,000 investment, I assume that means that the investor has a right to 20% of the profits.
Well, 20% of any profits distributed to the owners as dividends. The company's management can also decide to re-invest.
Would this $500,000 then be owned by the company or by the person who sold their 20% of the company?
It would be owned by whoever sold the 20% of the company. That might be a person or it might be the company.
Can the person who sold their 20% spend that money however they like (to buy personal property etc for themself) or must that $500,000 be spent by the company for company purchases and expenses?
If the seller was a person, they can do whatever they like with the money. The company is not significantly affected -- before person A owned 20% of it, now person B owns 20% of it.
If the seller was the company itself, then the company now has $500,000 more money but every previous owner now owns a smaller percentage of the company. These should be roughly equal in value. Presumably, the company only agreed to sell 20% of itself for $500,000 if it needed the money for some reason, so all the owners should be better off.
Say Alice and Bob each own 50% of a company and the company is worth $2 million. Alice and Bob each have $1 million in equity. Say the company needs some cash, so the company sells 20% of itself for $500,000.
The company now has $500,000 more than it did before, so should be worth $2.5 million. Alice and Bob each now own 40% of the company, worth $1 million (40% of $2.5 million equals 50% of $2 million). The buyer owns 20% of a company now worth $2.5 million, which is worth $500,000 (20% of $2.5 million is $500,000) -- the amount he paid.
Alice, Bob and the buyer now all have fair shares in the company, but the company has $500,000 more in cash. Presumably, Alice and Bob agreed to have their company do this because the company needed more cash for some reason.
Alice and Bob see no change in the value of their stock, it's still worth $1 million. But from now on, Alice and Bob will only get 40% of any future dividends instead of 50%, but presumably they felt this was a fair trade to get the company the cash it needed.
Alice or Bob, assuming the company allows such transfers, can each sell 20% of the company (now half their holdings) if they wish. They can do whatever they want with that money. The company's value and holdings are not affected.
So the short answer to your question, "Is money invested in a company owned by the company" is "Sometimes".