After "breaking through" the camp of the Philistines, it is highly unlikely these men were unscathed. When they returned from their dangerous journey, I imagine David looked at them all bloodied and battered and wondered what had happened. When they produced water from the well by the gate in Bethlehem, David was appalled they risked their lives and shed their blood for his sake. He looked at their bruises, lacerations and blood and felt unworthy to drink of the water that came at such a high price. The risk involved with going to Bethlehem was likely a reason why David had not gone to Bethlehem himself, and why David had not led his men to the well by the gate to quench his craving.
David would not treat their blood like water or a common thing, so he treated the water they brought him from Bethlehem as their precious blood. Though they urged him, David would not drink it. He poured out all the water from the well of Bethlehem as an offering before the LORD, elevating their service, love and sacrifice as a most worthy and honourable gesture, and David gave to God the honour the LORD is worthy of by giving him his best and what he desired and prized greatly. The thing David longed for he denied himself from drinking so God would be praised and glorified. God is worthy of such self denial, and David's act teaches us the very thing we long for that we could have--or even hold in our hands--is worth giving to God to honour and recognise His greatness and our allegiance to Him.
In response to what David's men did out of love and loyalty for their future king, David used the water to express his love for God. He denied meeting his physical needs and personal preferences to honour and praise the LORD in sincere worship. The humility of David shines in this passage, for he demonstrated his unworthiness to receive of such great personal sacrifice only God is worthy of. I do not believe it was a sin to drink the water from the well near the gate of Bethlehem, but David refused to do it because he loved God and others more than himself. Solomon mused in Proverbs 5:16 on the subject of sexual thirst: "Should
your fountains be dispersed abroad, streams of water in the
streets?" The answer of course is no: we ought to reserve the quenching of such thirst with our spouse alone. God is worthy of abstinence, chastity, and monogamy in marriage. Knowing Jesus has shed His blood to forgive us of all sin and filled us with the Holy Spirit, we are to keep our temple pure from fornication, pouring ourselves out as drink offerings unto our King Jesus.