In the late 1990’s Marvel was a publicly traded company where their shares were $3-4. They had recently exited bankruptcy and sold off the movie rights to Spiderman to Sony and the X-men to Fox.
Thanks to the success of Spiderman and X-Men, Marvel decided to fund their own productions, starting with Iron Man. They created the Marvel Cinematic Universe (MCU) where their characters could interact, which eventually led to the Avengers movie.
Marvel’s success caught the attention of Disney, who then bought them out. The only problem is that Sony and Fox still owned the rights to Spiderman and X-Men as long as they continued making movies. Sony had a hit with the first three Spiderman movies starring Tobey Maguire. They did less and less business with Andrew Garfield as part of a two film reboot.
Since Marvel realized that Sony would never give up Spiderman the way Fox gave up Daredevil, Marvel was able to come to a deal where Spiderman would continue to be released by Sony, but be part of the MCU. Sony would pay Marvel a flat producing fee, keep the box office, and cede merchandising back to Marvel. It was a brilliant idea especially when Spiderman was quickly added to Captain America: Civil War. One can only hope that Marvel can come to a deal with Fox once there is the inevitable X-Men reboot. One can also hope that Fox gives back the Fantastic Four movie rights to Marvel after whiffing three times already.
Spiderman: Homecoming is a box office and critical smash because Marvel Studios knows how to make movies.