Diamond is the hardest natural material on Earth. The "lead" in a pencil is soft enough to rub off on paper. Both are made of nothing but carbon atoms. So how can they be so different?
The answer is in how the atoms are joined.
In diamond, every carbon atom uses all four hands to grip four other carbon atoms. The bonds point in every direction, so the whole crystal is one giant, rigid network. To scratch it you would have to break a huge number of bonds. That is why diamond is so hard.
In graphite, each carbon atom bonds to only 3 neighbours, in flat sheets of hexagons. Its fourth outer electron is shared across the whole sheet, which is why graphite conducts electricity. The sheets are stacked like pages, held together by a weak pull, so they slide over each other easily. When you write with a pencil, sheets of graphite slide off onto the paper.