The best teams get the best results, and so can both attract more sponsorship, and afford to pay the best riders. The best teams don't even need to pay more than others, as we saw with Ducati - Rossi and Lorenzo have both already turned down big paydays from Ducati to ride for Yamaha. Lorenzo and Marquez will do the same again this year.
It's much more about the team than the bike, though. The team which can figure out how to adapt the bike best to the conditions wins most, and that's the team with the most flexible minds. The best teams, of course, also attract the best mechanics and engineers, because they are just as competitive as the riders.
Of course, the fact that the factory teams have an army of people analyzing the data and looking for ways of improving makes a big difference.
If you think it's only about the bike, take a look at Moto2. Identical engines, nearly identical bikes, often identical suspension, brakes, etc. Only difference is the riders and the teams. And that difference is somewhere north of 2 seconds a lap.
If you don't believe me, take a look at Mika Kallio, and the difference between 2014 (2nd in the championship, 3 poles, 3 wins, 10 total podiums) and 2015 (15th in the championship, no poles or podiums, best result, 4th in Argentina). He started both season on the same bike, a Kalex, but things got so bad in 2015 he jumped ship and went to QMMF to ride a Speed Up. Out of the frying pan, into the fire. His former teammate finished 3rd, and the championship was won by a rider on a Kalex, the one Kallio had abandoned.
That difference was all down to the team, and the interaction between Kallio and the team.
Or was it all a sham and a fraud?