The horses that go with each horse to the gate are 'pony horses'. They are riders paid by the owner/trainer to accompany a race horse until the gate man (one assigned to each horse) come and takes hold of him and puts him in the gate. They help keep the race horse calm and they prevent a horse from running off because it has no running martingale in a race like it does when it gallops. A race horse warming up too fast or running off or fighting its jockey for 10 minutes because it wants to run would be detrimental to its upcoming race.
The two riders that stay in front of and behind the gate before and at the beginning are there to catch horses that throw their riders, break through the gate or 'get away' at or before the gate is loaded and ready to spring. They are called outriders and they are employees of the race track.