I don't know where it comes from, the only thing that I know is that they are killing bulls just for fun. And I don't like it.
Google can help with the explanation of the origins:
Originally, the festival was a deeply religious event honouring the life of a local bishop that was executed on Sept. 25, sometime in the third century in Amiens, France while evangelising and spreading Christianity. In the twelfth century, the anniversary of the execution began to be commemorated by a week long series of masses and processions in October. In classic Catholic style, worshippers are asked to remember the suffering and torment that San Fermin experienced while doing God's work.
The fiesta began to take on a lighter character, however, and became an event of dancing and drinking, a time when ordinary people could forget their troubles for a few days. In 1591, at the request of the people of Pamplona, the town council moved the celebration to the second week of July to take advantage of the milder weather.
By the eighteenth century, elements of Spain's bullfighting and rural culture began to show their influence. The fiesta became a time for farmers to set up a large market in the town. Bullfights, a traditional spectator sport, came to the forefront. The town square, where the fights would take place, would be fenced off, and the audience would climb the posts to get a better look.
The bulls had to be moved from the corrals to the main square for the fights. People would gather in the streets to see the pack of bulls as it moved through the streets. Armed with sticks, they would guide the animals to make sure none strayed. Soon, people began to run with and in front of the pack of bulls. Many believe this is where the running was born. The fiesta's present incarnation was made official in 1939, when the rockets described in The Sun Also Rises were set off by members of the Town Council.
Nobody expects the spanish inquisition!