Your forgetting about the liquidity of stocks and how price is controlled by perception.
Let's look at public markets as an example since they are the most liquid.
Stocks are freely traded on the open market and prices are determined by perception. Value is subjective.
This may seem irrational, but it's how the system works. Most investors are investing in the stock itself, meaning they want to see stock price appreciation (and owning a piece of the company is less of a consideration).
When someone buys a stock that doesn't pay dividends, they are betting on the future of the company. Take Amazon as an example. The stock price has more than tripled in the past decade because people are investing in the future of Amazon. In a way, it doesn't matter what the actual stock/ownership is worth as much as it matters that people think it's worth a certain price. I can't tell you how much money Amazon is worth, but I can tell you how much you can buy a share for.
Since shares are freely traded, investors can make money as the stock's price increases.
To answer your second question, offering equity DOES cost the company. We already discussed how public perception can impact the price of a stock. If a company issues unlimited shares, they will lose investors' faith, and the price could drop.
Furthermore, selling more equity has measurable impacts on stock price fluctuation. Stock prices fluctuate relative to supply and demand. When demand outweighs supply (i.e. more people want to buy than sell), the stock price goes up. If the company continues to issue new shares, they are increasing the supply and making it difficult for the stock price to increase. This is why investors and traders are always wary of secondary offerings.
This same logic applies to private funding, but there is lower liquidity since shares aren't traded on the open market.