alright folks lets plot this out chronologically
presumably the game begins with this confrontation with bowser, notice that peach is wearing her usual dress but not her usual crown, hmm...
so bowser totally fucks mario's shit like the boss he is, presumably knocking him off the airship. he even goes as far as to destroy the dude's hat
then he peaces the fuck out (im certain this comes after the hat stomping because peach is still in her regular dress)
here comes the big question: did mario fucking die? i dunno man, he's seen in this spooky black and white world with a ghost thing. this is presumably where mario meets cappy for the first time (notice mario's lack of hat from bowser destroying it)
cappy doesn't seem too impressed with how he looks on his new host, so using a piece of mario's ruined hat, he turns into a shiny new hat!
now mario can use cappy's abilities to possess whoever he tosses his hat at