They're drilled from the earth. The Earth that they turn into magnets still has gravity left in it, causing them to attract. However since gravity is focused on the core, when you drill them out, only half of the magnet has gravity in it. Same poles dont repel, but rather just pull away from each other