This is one of my favourite sayings - the times it happens to me...
I take it to mean: if you do someone a favour, then events will conspire to make you a worse off than if you hadn't done the favour. NB, usually it isn't a deliberate act on the part of the receiver of the good deed.
A simple example: if you're in a queue of traffic running up to some lights, and you let someone out of a side road into the queue in front of you, the lights will change so that they get through and you are stopped.