Those are the creatures that Vanitas
created from the pure negative energy(such as, emotions, feelings, and thoughts) of a person. Since, Vanitas is made-up of pure darkness, so he can control and manipulate and make some creatures like these.
Vanitas created them in order to make Ventus
, and Terra
to become more powerful. Specially to Ventus and Terra.
For Ven's case, Vanitas encouraged Ven to run after Terra so, Ventus would leave Master Eraquis
's place, and become stronger by fighting those Unversed that he created. And at the same time, Vanitas's power of darkness will grow when they defeating Unversed.
In Terra's case, Master Xehanort
needed Terra to be his next vessel. For that reason, He tested Terra's darkness.