Miners need to pay for costs, namely electricity and hardware. One such way to pay for these is to sell the Bitcoin they mine for regular money.
Such transactions will often pass through exchanges. Exchanges and ATMs are simply order books. They accept Bitcoin and fiat money, and match buyers and sellers. If you want to sell 1 BTC at $1000, the order will only go through if there is a buyer willing to pay $1000 for 1 BTC.
Exchange will rarely hold large positions themselves. Instead, all the funds on an exchange usually belong to buyers and sellers, which can be miners, or people who have previously bought Bitcoins.
ATMs and other such systems will often just be a more user friendly mask to an exchange. An ATM operator might deposit $100,000 into an exchange account. Then, when someone puts $100 into an ATM, the ATM operator will execute a buy order of $100 on the exchange (out of their 100k balance). If the order is successful, the ATM will send the BTC out to the user's address, usually from a "hot wallet", which contains some prepurchased BTC that is readily accessible (also commonly known as the "float").
The ATM operator will then perform some balancing of their own, which may involve moving the BTC purchased on the exchange to their hot wallet, and moving the $100 physically deposited into the ATM into a bank account, and then transferring to the exchange he/she uses to maintain liquidity.
At the end of the day, if you follow transaction inputs back long enough, you will eventually end up at a coinbase input, which is the block mining reward that created some BTC. This till then pass through an assortment of exchanges, personal wallets, and p2p trades until it finally ends up with you.