You are correct when you say that mocking someone is imitating them but imitate has a negative meaning, the intention is to make fun of them, to ridicule them.
Cambridge Dictionary online:
Mock: to laugh at someone, often by copying them in a funny but unkind way.
When you imitate someone you copy them without any negative intent.
Cambridge Dictionary online:
Imitate: to behave in a similar way to someone or something else, or to copy the speech or behaviour, etc. of someone or something.
I knew a girl like you, who was so ahead of her time. So different. People mocked her.
→ People used to imitate the girl to make fun of her because they found she was different from them.
Until the day they all found themselves imitating her.
→ One day they stopped mocking her, they still copied what she did but without intent to make fun of her, they had changed their feelings towards her, it might even imply they now imitated her because they admired her.