It's important to note that there can be lots of variations in a given, specific scenario. Dealers may behave differently on different deals over time, and there may be specific reasons behind that which we will never know.
That said, speaking generally, the biggest reason why dealers prefer finance for some cases is when they are getting a kickback from the lender. Often, a dealer will push the in-house lender (i.e. Ford Motor Credit Company at a Ford dealership). Or, they may have a relationship with a different lender. These relationships are often built on the dealer receiving an incentive for every loan they sell. Sometimes, a portion of the incentive is meant to be passed on to the customer. For instance, the bank may say, we will give you $1,800 for every loan you sell, if you agree to pass $1,500 of that on to the customer as a discount.
In those cases, it's pretty clear why the dealer will prefer financing, and it's also clear why they will only give you a discount if you finance.
But there may be more subtle reasons why dealers prefer one payment method over another. For instance, they may have a "favorite" bank that they work well with, who responds quickly and funds loans quickly. They may push you towards that bank out of convenience.
Also, banks generally pay origination fees to dealerships when the dealer sells the loan. These fees are usually in the range of a few hundred dollars, and they're usually a part of the contract between the bank and the dealer, and are separate from specific promotions as described above. The dealer may be willing to write off their own cost to sell the loan, in which case that fee is seen as pure profit, and the dealer has an incentive to get you to finance the vehicle.
You didn't mention credit cards, but it's typical for dealers to dislike payment by credit card, since that means that they will lose on the interchange fee, which is typically about 3% of a large transaction. That may be their entire profit margin on a new car, so they will be reluctant to take it.
Cash typically represents a completely neutral deal - there's no way to hide profit or incentives in a cash deal, since the customer is literally making a direct payment for the entire sale price. Dealers who have no bank-funded incentives may like cash more than other payment methods, but dealers who are operating with heavy incentives available from banks may prefer to push customers away from cash deals.
Before you take a loan as part of an incentive deal, with the intention of paying it off in full immediately, make sure you understand the terms and conditions of the loan. Some lenders will implement a prepayment penalty, which could erode your incentive.