This is because glass rod acquires positive charge but ebonite rod gets negatively charged. Due to these opposite charges, both rods attract each other. If another rod with similar charge as that of glass rod is brought near to it, they will repel each other.
Like charges repel each other but opposite charges attract each other.