That depends on what people are willing to pay for them. A large portion of what people think a stock is worth is based on earnings and earnings expectations. This includes what a company has earned, what it is earning currently and what it might earn in the future.
So, it’s not just a random guess, but somewhat based on facts, knowledge and information. How aggressive is the company? How skilled is the CEO? Is the company’s market growing? How much is the company going to pay its shareholders in dividend? How big is the company’s debt or exposure to other creditors?
Then you might want to look outside the company and investigate the market and overall economy itself. Is the company trading in shrinking market/industry? And what about their competition, are they growing or shrinking?
Finally you also should consider general business factors. For example, will rising costs of labour and raw materials impact their profit?
These are just some of the many complex questions to which the intelligent investor wants answered in order to have a reliable opinion of what the company might be worth tomorrow.
After careful analysis, you might not agree with the price at which a particular stock is selling. You might think it’s too high or too low. What that stock sells at, is a total sum of all the individual judgements about the price. The price is nothing more than the expression of what people want to buy or sell.
If now many people or market participants decide that a stock is overpriced, they may decide to sell that stock. In doing so, the price will drop and this can be further exaggerated due to the dominance of the computer trading. This might cause other people to sell that same stock (trend following or herd mentality). This can cause the stock price to fall strongly or can lead to stock market crashes like the famous one in 1929 or 1987 or GFC ten years ago.