I listen to a podcast that has a theory about this. The comedy in those kind of movies was always there, it just changed form.
Prior to the sort of wry, Joss Whedon-esque dialogue tons of action movies used slapstick for levity. The verbal jokes were the domain of comedy movies.
Then after Avengers made a billion dollars studios started aping the style and comedy as a genre in Hollywood just sort of stopped existing in favor of dramedy and action-comedy.