From the Super Mario Wiki
The Mushroom Derby is a race that takes place on Yo'ster Isle in Super Mario RPG: Legend of the Seven Stars. Mostly, only Yoshis participate in the Mushroom Derby (however, the Yoshis may have riders accompany them during the race). The steps in the race have to follow the music that is playing in the background. A Yoshi can boost its speed with a Yoshi Cookie. The winner also gets cookies rewarded.
During the race, Mario rides on Yoshi's back, helping him defeat Boshi. To beat Boshi to the finish line, Yoshi has to move to the beat of the derby's music. As the music plays, the player must alternate between and with the music's tempo. If the player presses the buttons too fast, Yoshi does not move. As the song plays, the beat may stop or change. The player must continue pushing the buttons to the original beat, not the new beat, however. Additionally, if Mario has any additional Yoshi cookies, he can feed them to Yoshi, giving him a boost of speed.