A compass needle is a small magnet. When it is free to turn and no other magnets are near, it always settles pointing roughly north. It does this because it lines up with a magnetic field, and the field is the Earth's own magnetic field. A compass needle lines up with a magnetic field, and the field around the Earth has the shape of a bar magnet's field, so the Earth behaves like a giant magnet.
The Earth's magnetic field has a shape like the field of a bar magnet. The cause of the field must be inside the Earth. The Earth's core is made mainly of the magnetic metals iron and nickel, and it is the only part deep inside the Earth made of magnetic material, so the field must come from the core. This fits the evidence from compasses: the field has to come from magnetic material, and the core is made of magnetic material, so the core must be magnetic.
The north pole of a compass points towards the geographic north pole of the Earth. We know unlike poles attract, so the magnetic pole of the Earth near the geographic north is actually a magnetic south pole. Both facts, the compass pointing north and the field looking like a bar magnet field, are evidence that the Earth has a magnetic core.