A charged object attracts a neutral object...but why do they repel afterwards?

If they touch, the excess charge goes to the uncharged...meaning both are now the same charge and of course repel.

The initial attraction is due to induced polarization of the neutral object.

When a charged object attracts a neutral object, it is because the charged object has an excess or deficit of electrons, resulting in an imbalance of electric charges. This imbalance creates an electric field around the charged object, which interacts with the charged particles within the neutral object, causing them to rearrange.

Initially, the neutral object has an equal number of positively charged protons and negatively charged electrons, resulting in a balanced distribution of charges. However, when the negatively charged electrons are attracted to the positively charged object, they move closer to it, creating an excess of positive charges on the side nearest to the charged object and an excess of negative charges on the opposite side.

This redistribution of charges results in an electric dipole, with one side of the neutral object becoming more positively charged and the other side becoming more negatively charged. Since unlike charges attract each other, the positively charged side of the neutral object is attracted to the negatively charged charged object.

Afterwards, when the neutral object gets close to the charged object, the excess charges on the neutral object can interact with the charges on the charged object. If the charges on the neutral object repel the charges on the charged object, the neutral object will also experience a repulsive force. This repulsion occurs because like charges repel each other, and the excess charges on the neutral object and the charged object have the same type of charge (either both positive or both negative).

In summary, when a charged object attracts a neutral object, it is due to the initial attraction between opposite charges. However, after the neutral object gets close to the charged object, the repulsion occurs because the excess charges on both objects have the same type of charge, leading to a repulsive force.