Legend says it derives from an old Monty Python skit, "Spam Spam Spam". Two customers in a cheap café trying to order from a menu that includes Spam in every recipe.
MENU:
Egg and bacon
Egg, sausage and bacon
Egg and Spam
Egg, bacon and Spam
Egg, bacon, sausage and Spam
Spam, bacon, sausage and Spam
Spam, egg, Spam, Spam, bacon and Spam
Spam, Spam, Spam, egg and Spam
Spam, Sausage, Spam, Spam, Spam, Bacon, Spam, Tomato and Spam
Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam
Lobster Thermidor aux crevettes with a Mornay sauce, garnished with truffle pâté, brandy and a fried egg on top, and Spam.
Here is a quotation from some Q&A column:
As to why unsolicited email is called spam, it's because its ubiquity is reminiscent of the meat mentioned in Monty Python's "Spam Song"