There are two main reasons. One is a phenomenon known as ‘travel and arrive’ – where investors buy a company’s shares ahead of its results because they believe the company might do well (perhaps they’ve spoken to customers and heard good things, or a supplier’s said that demand for its products is rising). This demand for the shares could cause them to rise.
Once the results do arrive, investors may want to lock in their positive returns by selling their shares, hoping other investors want to buy based on the company’s good report – but if there are more sellers than buyers, that could lead the stock price to fall.
Another big reason is a company’s outlook. If a company exceeds expectations but warns that its future sales or profit won’t be as high as investors expect (like Nvidia), then investors may well sell – the company’s unlikely to be as valuable as they’d previously thought, resulting in a falling stock price.