While in the Jakku system, Rey had to repair the Falcon, and asked Finn where the Resistance base was. Not knowing the answer, he admitted to BB-8 (but not to Rey) that he wasn't part of the Resistance and asked where the base was. After some debate, BB-8 revealed the base's location in the Ileenium system.
So, why do they go to the Maz's castle, if they already knew the coordinates of the Resistance base?
And, at this particular time, i'm not sure, but I think they don't know what BB8 contains (the map), neither that the first goal of the resistance is to find Luke or that Rey has a link with the Force.
So why do they go in another place than the resistance base in the Ileenium system ?So why do they go to the Maz's castle, rather than the Resistance base?