Which way does a compass point in space?
Magnetic field strength decreases away from any magnet (eg. earth) inversely proportional to the square of distance so in the ordinary sense of understanding the word space, there would be no preferential direction of pointing for the needle. However, solar energy flux includes magnetic particles such as are responsible for the aurora borealis on earth so it is conceivable that the needle may fluxuate in response to passing magnetic particles.
A compass in space would point towards the same thing it points to on Earth -- the north pole of the strongest available magnetic source.
On Earth, that is usually the Earth's magnetic north pole since the planet itself acts as a giant magnet. In space, it would align itself with whatever was near enough to have a magnetic influence, perhaps an iron-filled asteroid or nearby star.
i hope you do not take offense, To that that comes hereafter; 'Tis only that it's my two-cents, Not one penny more thereafter. §;o) I think it would point to the nearest mass of metal like maybe the spaceship.
Along the field lines of the largest nearby magnetic field - quite likely the planet it is in orbit of (if any!)
I would imagine... toward the nearest celestial body with a magnetic field...