What sets the maximum masses of planetary cores?