The drug dealer gives you a free hit because it is profitable for him in the long term for you to be addicted to his product, not because he is your friend.
Another way to look at it is they are running a business. It's not even close to gambling for example.
It's weird to me how often this analogy gets used because:
1. In most cases, like this one, the product isn't heroin.
2. Drug dealers don't actually do that.