The impressions that Pip carried around of Magwitch for years were of a brutal, dirty, conniving, threatening criminal who forced him to steal. He first met Magwitch as an impressionable boy, and in his imagination, Magwitch was like the boogey man, terrifying and horrible, something that he wanted to forget. So, when he discovers that Magwitch was his benefactor, he has a really hard time correlating that evil criminal with someone who would be so benevolent. Besides, Magwitch is submissive, a bother, and putting Pip in a difficult situation as he houses a known and wanted felon. It is stressful.
There are a couple factors that change Pip's attitude towards Magwitch. First of all, learning that he is Estella's father, who was abused and harmed by the same man that gypped Miss Havisham; that made Pip sympathize with the man a bit more. It helped him to see him in the light of not a brutal criminal, but a man fallen on hard times in order to survive. Secondly, Magwitch's total and complete devotion and loyalty to Pip warms Pip to him a bit. Magwitch wants so badly for Pip to be happy, and risked his life and limb to ensure it would happen. Third, Magwitch really tried to reform himself, and had spent the previous years working hard to earn money. Fourth, Pip himself had been humbled by his own judgmental nature; he had recently realized just how horribly he had treated Joe and Biddy, and he realized that he needed to look more kindly on people that, on the surface, might not be his first choice of friends.
So, a combination of circumstances, hard times, and revealed character background turn Pip's opinion to Magwitch's favor, and he is able to stay by his side as a true friend. I hope that helped; good luck!