Static electricity is an electric phenomenon in which charged particles are transferred from one body to another.
Rubbing causes the charges to move from one body to another, hence creating static electricity.
When you rub two insulating materials the different atoms get close enough that it is energetically favorable for them to exchange electrons. Then when you pull them apart the electrons stay put and the objects both have a net charge (one positive, one negative).