Sometimes boys don't know how to handle a situation, and do something that will break a girl's heart.
Sometimes, they are spiteful or angry enough to do it, whether deliberately or just in a rage.
Sometimes, they will not even know they have done it, because they didn't know how you felt, or had interpreted it the wrong way, or didn't (or didn't want to) feel the same way about you.
Sometimes, having your heart broken a little now is better than having it broken much worse later on; a few guys will recognise that and see it as the lesser of two evils, others will simply do that as they go.