A magnetic compass has a needle that is a small magnet. When it is a long way from other magnets, the needle always settles pointing towards the north. This means the compass is lining up with a magnetic field that is present everywhere on the surface of the Earth.
The north-seeking end of the needle is a north pole. Unlike poles attract, so it is attracted towards a south magnetic pole. The Earth's magnetic field is like the field of a giant bar magnet, with a magnetic south pole near the geographic North Pole. That is why the needle's north end points towards geographic north.
A compass can only turn in this way if there is a magnetic field to act on it. Since the field is found all over the Earth and looks like a bar magnet's field, the source must be inside the Earth. The core of the Earth is made mostly of iron and nickel, both magnetic metals. So the behaviour of a compass is evidence that the core of the Earth must be magnetic.