I have encountered some cases where if I have paid with a credit card, the business may charge a higher amount to the card than what was authorized.
Sellers know that memory is fallible and without a receipt I may be unlikely to accurately remember the correct amount of the charge to check my credit card statement, especially if the amount they actually charge is not extravagantly higher. They also know that even in the unlikely case I do remember all the details, do check, and notice that they've charged more, I don't have a copy of the receipt to be able to contradict the credit card statement or practically win a dispute through the credit card company.
If I do take the receipt, I have the capacity to check it against the credit card statement and contest any overcharge, and the business knows this. If the business is invested in keeping a low-level fraud going without detection for as long as possible (so as to maximize profits from the activity), the business will only apply the overcharge to customers who declined to take receipts.
Thus, even if I never actually do check that transaction, I am more protected from this kind of fraud than I would be if I refused the receipt. Paying cash offers even stronger protection against later changes to the amount.
I have seen cases in which a shopkeeper allows someone to purchase an item with cash without accepting a receipt and attempt to leave, then accuses the customer of stealing. The customer might be offered the choice of (a) arrest and a trip to the local jail while the details are sorted out, or (b) paying some amount of money, often related to the total asking price for the goods they were attempting to leave with, and/or the amount of remaining cash the shopkeeper knows the customer has. Due to the monetary and nonmonetary costs associated with (a), many people will choose (b), or at least a negotiated version of (b) with a lower cost than initially demanded.
Again, a business invested in keeping this racket going will only pick targets who don't have a receipt they can use as defense evidence.
(I've also seen the version where a seller of expensive small things, like jewels/jewelry, will take out many samples to show a prospective customer, and then if the customer doesn't buy, the seller will put everything away, pocketing/hiding one of the items when the non-customer's distracted, then "discover" it missing and accuse the non-customer of stealing. A receipt won't help in that case, though.)
I have seen cases where it is important to get a receipt from a service business (e.g. short-term bicycle rental) especially when paying cash, because the employees might pocket the funds and underreport sales to their employer, making the customer who doesn't take the receipt an unwitting assistant to theft from the business they may be trying to support. This seems less likely when a recording electronic cash register or electronic payment is used, but such registers aren't universal, and if you declare that you don't want the receipt your transaction might not be processed through a recording register.
In my understanding, this was the original purpose for the receipt, allowing a customer to notify the business owner to be on the lookout for those funds in the business's cash box, helping keep employees honest whether or not that notice actually occurred for any particular transaction. I have never seen such notice happen in practice, even while the fraud it is intended to prevent does.
Businesses may be more likely to conduct low-level fraud against tourists, who are much less likely than locals to return to the vendor for future business even if everything goes well, and less likely to be able/willing to take any action in the legal system of the jurisdiction they are visiting.
I believe these kinds of dishonest treatment are less likely to happen in Germany than in some other places, and do not believe a customer generally has any legal duty to accept the receipt (unless they plan to e.g. claim the purchase as a tax deduction), but I find accepting the receipt to be generally good practice.
If you are purchasing durable goods with a warranty, you may need the receipt to prove the date of purchase and amount paid for that item, which a credit card statement might not show as clearly.
If you purchased an expensive commodity and then see the same item cheaper from another vendor shortly thereafter, AND your credit card is one of the few offering a cross-vendor price-match program which covers the purchased item, you would need your receipt to make a claim under that program.
If you plan to cross a customs-controlled border with the goods you are purchasing, you may legally need the receipt to prove the value of the goods in order to demonstrate that your imports are under a duty-free exemption and/or reduce the probability that your duties will be assessed on a value higher than your recent market price for that item. This is less important for consumables you will eat/use before departing.