"To answer this psychologically, Karen Horney believed that there are 3 neurotic trends, one of which is "moving away from people" to defend against isolation. In order to defend themselves against being dependance, a person will try to develop self-sufficiency. So to answer your question, a person might push people away when they need them in order to alleviate the fear of depending on others. To dumb it down a little bit, they try fight the fear of being alone, by trying to become ok with being alone."
"You may have been badly hurt in the past and do not have much self-worth. Subconsciously, you may be testing the other person and seeing how they react. You may think that if they really love you they will accept you as you are. Possibly you are hurting them before they get chance to hurt you.
Whatever the reason, it is likely to affect you in every relationship. At least you recognise the problem and want to do something about it."
- The Original Online Glossy
true, that.