Your computer is solving math problems to make sure no one makes transactions on the Bitcoin network that aren’t true. The first to accurately guess the hash code gets to add a block and is rewarded with new bitcoin.
Mining requires high-powered hardware and a lot of electricity. Fluctuating energy prices cut into profit margins.