They are not necessarily the same thing actually. Although maybe people often associate both words to each other but they are miles different from each other.
Spam is just annoying junk in your email folder. They’re useless and most of the time harmless especially if you don’t interact with it. Not all spams are scams sometimes they are just trying to flood people with whatever they are advertising.
Scam on the other hand is very harmful and will extort your money or data or whatever it is they want from you. They are associated with each other because most scams are from spams.