In universe, or maybe meta universe is a better term, Spider-Man serves to welcome the new book into the Marvel continuity. Spider-Man is THE most iconic Marvel character, period. Having Spider-Man guest star means a metaphoric 'welcome to the neighborhood, new guys'. At least in the case of Transformers, there is a certain irony with that aspect of the guest spot. Transformers (at least, G1 Marvel Transformers) would never be closer to the mainstream Marvel continuity than issue #3, with Spider-Man costarring and a Nick Fury cameo. Aside from that, you've got a Dazzler throw-away reference in #2, mutants in #67 - #80, and the Death's Head stories over in the Marvel UK stories. Even then, though, before Death's Head could interact with mainstream Marvel characters he had to be shrunk down to size by The Doctor.
Decades later, of course, there would be the Avengers / Transformers crossover, though this would involve the IDW Transformer continuity, and a series of Marvel Transformers toys, though they don't exist in any fiction outside of toy bios.
The out of universe reason is much more straightforward: to sell comic books. Comic books are ordered three months ahead of time, which means that retailers are ordering copies of #3 before the first issue has even hit the shelves. Ordering comics, sight unseen, takes a lot of guesswork. The first issue of anything, especially in the 80s, was going to sell reasonably well. The second issue, most retailers would figure some percentage of the first issue and order that. Now, absent any other factors, they'd probably do the same and order even fewer copies of the third issue, resulting in bit of a death spiral for the book, with only the fourth issue having a chance to break out of it, and only then if the first issue was well received. A popular guest appearance can break that spiral. Retailers know that Spider-Man is a draw, so they up their orders from #2. Now the book has a fighting chance.
And there you have it. An unofficial induction into continuity, and a strategic attempt to boost sales of a key issue so that the title isn't doomed before it even hits shelves.